<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Node.js,框架,AngularJS," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x5199;&amp;#x5728;&amp;#x6700;&amp;#x524D;&amp;#xFF1A;&amp;#x7531;&amp;#x4E8E; ng &amp;#x7684;&amp;#x8868;&amp;#x8FBE;&amp;#x5F0F;&amp;#x548C;&amp;#x535A;&amp;#x5BA2;&amp;#x6709;&amp;#x51B2;&amp;#x7A81;&amp;#xFF0C;&amp;#x6240;&amp;#x4EE5;&amp;#x9664;&amp;#x4E86;&amp;#x4EE3;&amp;#x7801;&amp;#x5">
<meta property="og:type" content="article">
<meta property="og:title" content="AngularJS 框架">
<meta property="og:url" content="https://hongqinma.github.io/2015/06/18/26-AngularJS-框架/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x5199;&amp;#x5728;&amp;#x6700;&amp;#x524D;&amp;#xFF1A;&amp;#x7531;&amp;#x4E8E; ng &amp;#x7684;&amp;#x8868;&amp;#x8FBE;&amp;#x5F0F;&amp;#x548C;&amp;#x535A;&amp;#x5BA2;&amp;#x6709;&amp;#x51B2;&amp;#x7A81;&amp;#xFF0C;&amp;#x6240;&amp;#x4EE5;&amp;#x9664;&amp;#x4E86;&amp;#x4EE3;&amp;#x7801;&amp;#x5">
<meta property="og:updated_time" content="2016-12-23T01:21:31.360Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="AngularJS 框架">
<meta name="twitter:description" content="&amp;#x5199;&amp;#x5728;&amp;#x6700;&amp;#x524D;&amp;#xFF1A;&amp;#x7531;&amp;#x4E8E; ng &amp;#x7684;&amp;#x8868;&amp;#x8FBE;&amp;#x5F0F;&amp;#x548C;&amp;#x535A;&amp;#x5BA2;&amp;#x6709;&amp;#x51B2;&amp;#x7A81;&amp;#xFF0C;&amp;#x6240;&amp;#x4EE5;&amp;#x9664;&amp;#x4E86;&amp;#x4EE3;&amp;#x7801;&amp;#x5">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2015/06/18/26-AngularJS-框架/"/>


  <title> AngularJS 框架 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                AngularJS 框架
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-06-18T21:59:18+08:00" content="2015-06-18">
              2015-06-18
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/AngularJs/" itemprop="url" rel="index">
                    <span itemprop="name">AngularJs</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2015/06/18/26-AngularJS-框架/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/06/18/26-AngularJS-框架/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
            <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x5199;&#x5728;&#x6700;&#x524D;&#xFF1A;&#x7531;&#x4E8E; ng &#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x548C;&#x535A;&#x5BA2;&#x6709;&#x51B2;&#x7A81;&#xFF0C;&#x6240;&#x4EE5;&#x9664;&#x4E86;&#x4EE3;&#x7801;&#x5757;&#x4E4B;&#x5916;&#x6240;&#x6709;&#x7684;&#x5927;&#x62EC;&#x53F7;&#x7ECF;&#x8FC7;&#x4E86; <code>\</code> &#x8F6C;&#x4E49;&#xFF01;</p>
<h2 id="Angular-&#x4ECB;&#x7ECD;"><a href="#Angular-&#x4ECB;&#x7ECD;" class="headerlink" title="Angular &#x4ECB;&#x7ECD;"></a>Angular &#x4ECB;&#x7ECD;</h2><h3 id="&#x4EC0;&#x4E48;&#x662F;&#x6846;&#x67B6;&#x548C;&#x5E93;"><a href="#&#x4EC0;&#x4E48;&#x662F;&#x6846;&#x67B6;&#x548C;&#x5E93;" class="headerlink" title="&#x4EC0;&#x4E48;&#x662F;&#x6846;&#x67B6;&#x548C;&#x5E93;"></a>&#x4EC0;&#x4E48;&#x662F;&#x6846;&#x67B6;&#x548C;&#x5E93;</h3><p>&#x5E93;&#x662F;&#x7531;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x4E3B;&#x52A8;&#x4F7F;&#x7528;&#x5E93;&#x91CC;&#x9762;&#x63D0;&#x4F9B;&#x7684; API&#xFF0C;&#x5B8C;&#x6210;&#x4EE3;&#x7801;&#x529F;&#x80FD;&#x903B;&#x8F91;</p>
<p>&#x6846;&#x67B6;&#x91CC;&#x9762;&#x63D0;&#x4F9B;&#x4E86;&#x5404;&#x79CD;&#x5404;&#x6837;&#x7684;&#x5E93;&#xFF0C;&#x8FD9;&#x4E9B;&#x5E93;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x4F7F;&#x7528;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7531;&#x6846;&#x67B6;&#x53BB;&#x8C03;&#x7528;&#x4F7F;&#x7528;</p>
<h3 id="&#x4EC0;&#x4E48;&#x662F;-AngularJS"><a href="#&#x4EC0;&#x4E48;&#x662F;-AngularJS" class="headerlink" title="&#x4EC0;&#x4E48;&#x662F; AngularJS"></a>&#x4EC0;&#x4E48;&#x662F; AngularJS</h3><ul>
<li>&#x4E00;&#x6B3E;&#x975E;&#x5E38;&#x4F18;&#x79C0;&#x7684;&#x524D;&#x7AEF;&#x9AD8;&#x7EA7; <strong>JavaScript &#x6846;&#x67B6;</strong></li>
<li>&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x6784;&#x5EFA; <strong>SPA &#x5E94;&#x7528;&#x7A0B;&#x5E8F;</strong></li>
<li>&#x901A;&#x8FC7; <strong>&#x6307;&#x4EE4;</strong> &#x6269;&#x5C55;&#x4E86; HTML&#xFF0C;&#x901A;&#x8FC7; <strong>&#x8868;&#x8FBE;&#x5F0F;</strong> &#x7ED1;&#x5B9A;&#x6570;&#x636E;&#x5230; HTML</li>
<li><strong>&#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x4E0A;&#x89E3;&#x653E;&#x4E86; DOM &#x64CD;&#x4F5C;</strong></li>
<li>&#x6784;&#x5EFA;&#x66F4;&#x52A0;&#x52A8;&#x611F;&#x7684; HTML &#x5E94;&#x7528;&#x7A0B;&#x5E8F;</li>
</ul>
<p>AngularJS&#x662F;&#x4E3A;&#x4E86;&#x514B;&#x670D;HTML&#x5728;&#x6784;&#x5EFA;&#x5E94;&#x7528;&#x4E0A;&#x7684;&#x4E0D;&#x8DB3;&#x800C;&#x8BBE;&#x8BA1;&#x7684;&#x3002;AngularJS&#x6709;&#x7740;&#x8BF8;&#x591A;&#x7279;&#x6027;&#xFF0C;&#x6700;&#x4E3A;&#x6838;&#x5FC3;&#x7684;&#x662F;&#xFF1A;</p>
<ul>
<li>MVC</li>
<li>&#x6A21;&#x5757;&#x5316;</li>
<li>&#x81EA;&#x52A8;&#x5316;&#x53CC;&#x5411;&#x6570;&#x636E;&#x7ED1;&#x5B9A;</li>
<li>&#x8BED;&#x4E49;&#x5316;&#x6807;&#x7B7E;&#x3001;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x7B49;&#x7B49;</li>
</ul>
<h3 id="&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;-Angular"><a href="#&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;-Angular" class="headerlink" title="&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528; Angular"></a>&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528; Angular</h3><p>&#x4EE5;&#x524D;&#x6211;&#x4EEC;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>&#x4F20;&#x7EDF;&#x9875;&#x9762;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x64CD;&#x4F5C;&#x65B9;&#x5F0F;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">id</span>=<span class="string">&quot;txt_value&quot;</span> <span class="attr">type</span>=<span class="string">&quot;number&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">id</span>=<span class="string">&quot;btn_add&quot;</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x589E;&#x52A0;&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    (<span class="function"><span class="keyword">function</span>(<span class="params">window, document</span>) </span>{</div><div class="line">      <span class="keyword">var</span> txt = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#txt_value&apos;</span>);</div><div class="line">      <span class="keyword">var</span> btn = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#btn_add&apos;</span>);</div><div class="line">      btn.addEventListener(<span class="string">&apos;click&apos;</span>, <span class="function"><span class="keyword">function</span>(<span class="params">e</span>) </span>{</div><div class="line">        <span class="keyword">var</span> now = txt.value - <span class="number">0</span>;</div><div class="line">        now = now + <span class="number">1</span>;</div><div class="line">        txt.value = now;</div><div class="line">      });</div><div class="line">    })(<span class="built_in">window</span>, <span class="built_in">document</span>);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<p>&#x4EE5;&#x540E;&#x5C06;&#x4F1A;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>&#x4F7F;&#x7528;AngularJS&#x5B9E;&#x73B0;&#x81EA;&#x589E;&#x529F;&#x80FD;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;number&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;value&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">ng-click</span>=<span class="string">&quot;value=value+1&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&#x589E;&#x52A0;&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../bower_components/angular/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<h3 id="AngularJS-&#x4F18;&#x7F3A;&#x70B9;"><a href="#AngularJS-&#x4F18;&#x7F3A;&#x70B9;" class="headerlink" title="AngularJS &#x4F18;&#x7F3A;&#x70B9;"></a>AngularJS &#x4F18;&#x7F3A;&#x70B9;</h3><p>&#x4F18;&#x70B9;&#xFF1A;</p>
<ol>
<li>AngularJS &#x6A21;&#x677F;&#x529F;&#x80FD;&#x5F3A;&#x5927;&#x4E30;&#x5BCC;&#xFF0C;&#x81EA;&#x5E26;&#x4E86;&#x6781;&#x5176;&#x4E30;&#x5BCC;&#x7684;angular&#x6307;&#x4EE4;&#x3002;</li>
<li>AngularJS &#x662F;&#x5B8C;&#x5168;&#x53EF;&#x6269;&#x5C55;&#x7684;&#xFF0C;&#x4E0E;&#x5176;&#x4ED6;&#x5E93;&#x7684;&#x517C;&#x5BB9;&#x6548;&#x679C;&#x5F88;&#x597D;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x529F;&#x80FD;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x6216;&#x66F4;&#x6362;&#xFF0C;&#x4EE5;&#x6EE1;&#x8DB3;&#x5F00;&#x53D1;&#x8005;&#x72EC;&#x7279;&#x7684;&#x5F00;&#x53D1;&#x6D41;&#x7A0B;&#x548C;&#x529F;&#x80FD;&#x7684;&#x9700;&#x6C42;&#x3002;</li>
<li>AngularJS &#x662F;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x5B8C;&#x5584;&#x7684;&#x524D;&#x7AEF;MVC&#x6846;&#x67B6;&#xFF0C;&#x5305;&#x542B;&#x670D;&#x52A1;&#xFF0C;&#x6A21;&#x677F;&#xFF0C;&#x6570;&#x636E;&#x53CC;&#x5411;&#x7ED1;&#x5B9A;&#xFF0C;&#x6A21;&#x5757;&#x5316;&#xFF0C;&#x8DEF;&#x7531;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x7B49;&#x6240;&#x6709;&#x529F;&#x80FD;&#xFF1B;</li>
<li>AngularJS &#x662F;&#x4E92;&#x8054;&#x7F51;&#x5DE8;&#x4EBA;&#x8C37;&#x6B4C;&#x5F00;&#x53D1;&#xFF0C;&#x8FD9;&#x4E5F;&#x610F;&#x5473;&#x7740;&#x4ED6;&#x6709;&#x4E00;&#x4E2A;&#x575A;&#x5B9E;&#x7684;&#x57FA;&#x7840;&#x548C;&#x793E;&#x533A;&#x652F;&#x6301;&#x3002;</li>
</ol>
<p>&#x7F3A;&#x70B9;&#xFF1A;</p>
<ol>
<li>AngularJS &#x5F3A;&#x7EA6;&#x675F;&#x5BFC;&#x81F4;&#x5B66;&#x4E60;&#x6210;&#x672C;&#x8F83;&#x9AD8;&#xFF0C;&#x5BF9;&#x524D;&#x7AEF;&#x4E0D;&#x53CB;&#x597D;&#x3002;&#x4F46;&#x9075;&#x5B88; AngularJS &#x7684;&#x7EA6;&#x5B9A;&#x65F6;&#xFF0C;&#x751F;&#x4EA7;&#x529B;&#x4F1A;&#x5F88;&#x9AD8;&#xFF0C;&#x5BF9; &#x540E;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x5F00;&#x53D1;&#x7A0B;&#x5E8F;&#x5458;&#x53CB;&#x597D;&#x3002;</li>
<li>AngularJS &#x4E0D;&#x5229;&#x4E8E; SEO&#xFF0C;&#x56E0;&#x4E3A;&#x6240;&#x6709;&#x5185;&#x5BB9;&#x90FD;&#x662F;&#x52A8;&#x6001;&#x83B7;&#x53D6;&#x5E76;&#x6E32;&#x67D3;&#x751F;&#x6210;&#x7684;&#xFF0C;&#x641C;&#x7D22;&#x5F15;&#x64CE;&#x6CA1;&#x6CD5;&#x722C;&#x53D6;&#x3002;</li>
<li>AngularJS &#x4F5C;&#x4E3A; MVVM &#x6846;&#x67B6;&#xFF0C;&#x56E0;&#x4E3A;&#x5B9E;&#x73B0;&#x4E86;&#x6570;&#x636E;&#x7684;&#x53CC;&#x5411;&#x7ED1;&#x5B9A;&#xFF0C;&#x5BF9;&#x4E8E;&#x5927;&#x6570;&#x7EC4;&#x3001;&#x590D;&#x6742;&#x5BF9;&#x8C61;&#x4F1A;&#x5B58;&#x5728;&#x6027;&#x80FD;&#x95EE;&#x9898;&#x3002;</li>
</ol>
<h3 id="AngularJS-&#x4F7F;&#x7528;&#x573A;&#x666F;"><a href="#AngularJS-&#x4F7F;&#x7528;&#x573A;&#x666F;" class="headerlink" title="AngularJS &#x4F7F;&#x7528;&#x573A;&#x666F;"></a>AngularJS &#x4F7F;&#x7528;&#x573A;&#x666F;</h3><ul>
<li>&#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;</li>
<li>&#x590D;&#x6742;&#x7684;&#x540E;&#x53F0;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;<ul>
<li>CRUD&#xFF08;&#x589E;&#x52A0; Create&#x3001;&#x67E5;&#x8BE2; Retrieve&#x3001;&#x66F4;&#x65B0; Update&#x3001;&#x5220;&#x9664; Delete&#xFF09;</li>
<li>&#x7E41;&#x6742;&#x7684; DOM &#x64CD;&#x4F5C;&#x5904;&#x7406;&#x7684;&#x9875;&#x9762;</li>
</ul>
</li>
</ul>
<p>Angular &#x662F;&#x4E00;&#x4E2A;&#x7C7B; MVC &#x7C7B;&#x7ED3;&#x6784;&#x7684; JavaScript &#x6846;&#x67B6;&#xFF0C;&#x5EFA;&#x8BAE;&#x6784;&#x5EFA; CRUD &#x7C7B;&#x578B;&#x5E94;&#x7528;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528;&#x5B83;&#xFF0C;&#x800C;&#x5BF9;&#x4E8E;&#x90A3;&#x4E9B;&#x56FE;&#x5F62;&#x7F16;&#x8F91;&#x3001;&#x6E38;&#x620F;&#x5F00;&#x53D1;&#x7B49;&#x5E94;&#x7528;&#xFF0C;&#x4F7F;&#x7528; Angular &#x5C31;&#x4E0D;&#x5982;&#x8C03;&#x7528;&#x5176;&#x5B83; JavaScript &#x7C7B;&#x5E93;&#x65B9;&#x4FBF;&#xFF0C;&#x5982; jQuery&#x3002;</p>
<h3 id="AngularJS&#x8D44;&#x6E90;"><a href="#AngularJS&#x8D44;&#x6E90;" class="headerlink" title="AngularJS&#x8D44;&#x6E90;"></a>AngularJS&#x8D44;&#x6E90;</h3><ul>
<li>&#x5B98;&#x65B9;&#x6587;&#x6863;&#xFF1A;<a href="https://docs.angularjs.org/api" target="_blank" rel="external">https://docs.angularjs.org/api</a></li>
<li>AngularJS &#x4E2D;&#x6587;&#x793E;&#x533A;&#xFF1A;<a href="http://angularjs.cn/" target="_blank" rel="external">http://angularjs.cn/</a></li>
</ul>
<h2 id="SPA-&#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;"><a href="#SPA-&#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;" class="headerlink" title="SPA &#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;"></a>SPA &#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;</h2><p>SPA&#x5168;&#x79F0;&#xFF1A;<code>Single Page Application</code>&#xFF0C;&#x5355;&#x9875;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x3002;</p>
<p>&#x6240;&#x8C13;&#x7684;&#x5355;&#x9875;&#x5E94;&#x7528;&#xFF1A;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x5229;&#x7528; hash &#x505A;&#x7F51;&#x9875;&#x5185;&#x90E8;&#x5C40;&#x90E8;&#x5185;&#x5BB9;&#x7684;&#x66FF;&#x6362;</p>
<p>(1). &#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#x9002;&#x7528;&#x4F20;&#x7EDF;&#x7684;&#x8DEF;&#x5F84;&#xFF1F;</p>
<p>&#x539F;&#x56E0;&#x662F;&#x4F20;&#x7EDF;&#x7684;&#x8DEF;&#x5F84;&#x4F1A;&#x9ED8;&#x8BA4;&#x53D1;&#x540C;&#x6B65;&#x8BF7;&#x6C42;&#x8DF3;&#x8F6C;</p>
<p>(2). &#x4E3A;&#x4EC0;&#x4E48; hash &#x4E2D;&#x7684;&#x8DEF;&#x5F84;&#x90FD;&#x662F;&#x4EE5; / &#x5F00;&#x5934;</p>
<p>&#x539F;&#x56E0;&#x662F;&#x4E3A;&#x4E86;&#x533A;&#x5206;&#x666E;&#x901A;&#x7684; hash</p>
<h3 id="&#x4F20;&#x7EDF;&#x7684;&#x7F51;&#x7AD9;&#x6A21;&#x578B;&#xFF1A;&#x591A;&#x9875;&#x9762;&#x5E94;&#x7528;&#x6A21;&#x578B;"><a href="#&#x4F20;&#x7EDF;&#x7684;&#x7F51;&#x7AD9;&#x6A21;&#x578B;&#xFF1A;&#x591A;&#x9875;&#x9762;&#x5E94;&#x7528;&#x6A21;&#x578B;" class="headerlink" title="&#x4F20;&#x7EDF;&#x7684;&#x7F51;&#x7AD9;&#x6A21;&#x578B;&#xFF1A;&#x591A;&#x9875;&#x9762;&#x5E94;&#x7528;&#x6A21;&#x578B;"></a>&#x4F20;&#x7EDF;&#x7684;&#x7F51;&#x7AD9;&#x6A21;&#x578B;&#xFF1A;&#x591A;&#x9875;&#x9762;&#x5E94;&#x7528;&#x6A21;&#x578B;</h3><h3 id="SPA-&#x7F51;&#x7AD9;&#x6A21;&#x578B;"><a href="#SPA-&#x7F51;&#x7AD9;&#x6A21;&#x578B;" class="headerlink" title="SPA &#x7F51;&#x7AD9;&#x6A21;&#x578B;"></a>SPA &#x7F51;&#x7AD9;&#x6A21;&#x578B;</h3><ul>
<li>&#x7F51;&#x6613;&#x4E91;&#x97F3;&#x4E50;&#x5B9E;&#x4F8B;&#x89E3;&#x6790;</li>
</ul>
<p>&#x951A;&#x70B9;&#xFF1A;&#x7F51;&#x9875;&#x5185;&#x90E8;&#x5B9A;&#x4F4D;</p>
<ul>
<li><code>id</code></li>
<li><code>a.name</code></li>
</ul>
<h3 id="&#x5229;&#x7528;&#x951A;&#x70B9;&#x6539;&#x53D8;&#x7F51;&#x9875;&#x5185;&#x5BB9;"><a href="#&#x5229;&#x7528;&#x951A;&#x70B9;&#x6539;&#x53D8;&#x7F51;&#x9875;&#x5185;&#x5BB9;" class="headerlink" title="&#x5229;&#x7528;&#x951A;&#x70B9;&#x6539;&#x53D8;&#x7F51;&#x9875;&#x5185;&#x5BB9;"></a>&#x5229;&#x7528;&#x951A;&#x70B9;&#x6539;&#x53D8;&#x7F51;&#x9875;&#x5185;&#x5BB9;</h3><ul>
<li>window&#x5BF9;&#x8C61;&#x7684; <code>hashchange</code> &#x4E8B;&#x4EF6;</li>
<li><code>window.location</code> &#x62FF;&#x5230;&#x951A;&#x70B9;&#x7684;&#x5185;&#x5BB9;</li>
<li>&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7684; <code>hash</code> &#x663E;&#x793A;&#x4E0D;&#x540C;&#x7684;&#x5185;&#x5BB9;</li>
</ul>
<h3 id="&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x597D;&#x5904;"><a href="#&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x597D;&#x5904;" class="headerlink" title="&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x597D;&#x5904;"></a>&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x597D;&#x5904;</h3><ul>
<li>&#x63D0;&#x9AD8;&#x4E86;&#x6574;&#x4E2A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x54CD;&#x5E94;&#x901F;&#x5EA6;&#x3001;&#x589E;&#x52A0;&#x4E86;&#x7528;&#x6237;&#x4F53;&#x9A8C;</li>
<li>&#x91CD;&#x7528;&#x8D44;&#x6E90;</li>
<li>&#x65B9;&#x4FBF;&#x7EDF;&#x4E00;&#x63A7;&#x5236;&#x548C;&#x4EE3;&#x7801;&#x91CD;&#x7528;</li>
</ul>
<h3 id="&#x5982;&#x4F55;&#x5728;&#x7F51;&#x9875;&#x4E2D;&#x89E3;&#x6790;-URL-&#x5730;&#x5740;"><a href="#&#x5982;&#x4F55;&#x5728;&#x7F51;&#x9875;&#x4E2D;&#x89E3;&#x6790;-URL-&#x5730;&#x5740;" class="headerlink" title="&#x5982;&#x4F55;&#x5728;&#x7F51;&#x9875;&#x4E2D;&#x89E3;&#x6790; URL &#x5730;&#x5740;"></a>&#x5982;&#x4F55;&#x5728;&#x7F51;&#x9875;&#x4E2D;&#x89E3;&#x6790; URL &#x5730;&#x5740;</h3><ul>
<li><a href="http://www.baidu.com/a/b/c?foo=bar&amp;name=jack#/abc" target="_blank" rel="external">http://www.baidu.com/a/b/c?foo=bar&amp;name=jack#/abc</a><ul>
<li>&#x5B57;&#x7B26;&#x4E32;&#x64CD;&#x4F5C;</li>
<li>&#x6B63;&#x5219;&#x5339;&#x914D;</li>
<li>a DOM &#x5143;&#x7D20;&#x89E3;&#x6790;</li>
</ul>
</li>
</ul>
<h2 id="Angular-&#x7684;&#x5E94;&#x7528;"><a href="#Angular-&#x7684;&#x5E94;&#x7528;" class="headerlink" title="Angular &#x7684;&#x5E94;&#x7528;"></a>Angular &#x7684;&#x5E94;&#x7528;</h2><h3 id="&#x5173;&#x4E8E;&#x7248;&#x672C;"><a href="#&#x5173;&#x4E8E;&#x7248;&#x672C;" class="headerlink" title="&#x5173;&#x4E8E;&#x7248;&#x672C;"></a>&#x5173;&#x4E8E;&#x7248;&#x672C;</h3><ul>
<li><a href="https://angularjs.org/" target="_blank" rel="external">Angular 1</a></li>
<li><a href="https://github.com/angular/angular.js" target="_blank" rel="external">Angular 1 - Github</a></li>
<li><a href="https://angular.io/" target="_blank" rel="external">Angular 2</a></li>
</ul>
<h3 id="&#x5B89;&#x88C5;"><a href="#&#x5B89;&#x88C5;" class="headerlink" title="&#x5B89;&#x88C5;"></a>&#x5B89;&#x88C5;</h3><ul>
<li>github<ul>
<li><code>https://github.com/angular/angular.js/releases</code></li>
</ul>
</li>
<li>CDN<ul>
<li><code>https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js</code></li>
</ul>
</li>
<li>bower<ul>
<li><code>bower install angular#1.5.8</code></li>
</ul>
</li>
<li>npm<ul>
<li><code>npm install angular@1.5.8</code></li>
</ul>
</li>
</ul>
<h3 id="&#x7B2C;&#x4E00;&#x4E2A;-Angular-&#x7A0B;&#x5E8F;"><a href="#&#x7B2C;&#x4E00;&#x4E2A;-Angular-&#x7A0B;&#x5E8F;" class="headerlink" title="&#x7B2C;&#x4E00;&#x4E2A; Angular &#x7A0B;&#x5E8F;"></a>&#x7B2C;&#x4E00;&#x4E2A; Angular &#x7A0B;&#x5E8F;</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>ng - HelloHiraku<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span> <span class="attr">ng-init</span>=<span class="string">&quot;name=&apos;World&apos;&quot;</span>&gt;</span></div><div class="line">  Name: <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;name&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">hr</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">h1</span>&gt;</span>Hello {{name}}!<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<h3 id="&#x4EE3;&#x7801;&#x89E3;&#x6790;"><a href="#&#x4EE3;&#x7801;&#x89E3;&#x6790;" class="headerlink" title="&#x4EE3;&#x7801;&#x89E3;&#x6790;"></a>&#x4EE3;&#x7801;&#x89E3;&#x6790;</h3><ul>
<li>&#x5F53;&#x7F51;&#x9875;&#x52A0;&#x8F7D;&#x5B8C;&#x6BD5;&#xFF0C;AngularJS &#x81EA;&#x52A8;&#x5F00;&#x59CB;&#x6267;&#x884C;</li>
<li>HTML &#x9875;&#x9762;&#x4E2D; <code>ng-xxx</code> &#x7684;&#x5C5E;&#x6027;&#x79F0;&#x4E4B;&#x4E3A;&#x6307;&#x4EE4;&#xFF08;Directive&#xFF09;</li>
<li><code>ng-app</code> &#x6307;&#x4EE4;&#x544A;&#x8BC9; AngularJS &#xFF0C;<code>&lt;body&gt;</code> &#x5143;&#x7D20;&#x662F; AngularJS &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7BA1;&#x7406;&#x7684;&#x8FB9;&#x754C;</li>
<li><code>ng-init</code> &#x6307;&#x4EE4;&#x521D;&#x59CB;&#x5316; AngularJS &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x53D8;&#x91CF;</li>
<li><code>ng-model</code> &#x6307;&#x4EE4;&#x628A;&#x6587;&#x672C;&#x6846;&#x7684; <code>value</code> &#x503C;&#x7ED1;&#x5B9A;&#x5230;&#x53D8;&#x91CF; <code>name</code> &#x4E0A;</li>
<li><code>\{\{ name \}\}</code> &#x8868;&#x8FBE;&#x5F0F;&#x5C31;&#x662F;&#x628A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x53D8;&#x91CF; <code>name</code> &#x7ED1;&#x5B9A;&#x5230;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#x7684; <code>innerHTML</code></li>
</ul>
<blockquote>
<p>ng &#x4F7F;&#x7528;&#x8FC7;&#x7A0B;</p>
</blockquote>
<p>(0). &#x5F15;&#x5305;</p>
<p>(1). &#x5728; body &#x4E0A;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#xFF1A;ng-app</p>
<p>(2). &#x5728; body &#x4E2D;&#x5199;&#x4E00;&#x4E2A; <code>&lt;h1&gt;\{\{&apos;Hello &apos; + &apos;World!&apos;\}\}&lt;/h1&gt;</code></p>
<p>&#x89E3;&#x6790;&#x8FC7;&#x7A0B;&#xFF1A;</p>
<ol>
<li>&#x6D4F;&#x89C8;&#x5668;&#x4ECE;&#x4E0A;&#x5230;&#x4E0B;&#x4F9D;&#x6B21;&#x89E3;&#x6790; DOM &#x6587;&#x6863;</li>
<li>&#x5F53;&#x6D4F;&#x89C8;&#x5668;&#x89E3;&#x6790;&#x5230; body &#x4E0A;&#x6709;&#x4E00;&#x4E2A; ng-app &#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x4E8E;&#x4E0D;&#x8BC6;&#x522B;&#x7684;&#x5C5E;&#x6027;&#x4F1A;&#x9009;&#x62E9;&#x5FFD;&#x7565;</li>
<li>&#x5F53;&#x6D4F;&#x89C8;&#x5668;&#x89E3;&#x6790;&#x5230; <code>&lt;h1&gt;\{\{&apos;Hello &apos; + &apos;World!&apos;\}\}&lt;/h1&gt;</code> &#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x65E0;&#x6CD5;&#x8BC6;&#x522B;&#x91CC;&#x9762;&#x7684;&#x53CC;&#x82B1;&#x62EC;&#x53F7;&#x4EE5;&#x53CA;&#x91CC;&#x9762;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x4F1A;&#x628A;&#x5B83;&#x5F53;&#x6210;&#x666E;&#x901A;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8FDB;&#x884C;&#x6E32;&#x67D3;</li>
<li>&#x5F53;&#x6D4F;&#x89C8;&#x897F;&#x53D1;&#x73B0; script &#x6807;&#x7B7E;&#x6307;&#x5B9A;&#x7684; angular.js &#x5F15;&#x7528;&#x6587;&#x4EF6;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x4E0B;&#x8F7D;&#x8BE5;&#x6587;&#x4EF6;</li>
<li>&#x5F53; angular.js &#x7A0B;&#x5E8F;&#x4E0B;&#x8F7D;&#x6210;&#x529F;&#x4E4B;&#x540E;&#xFF0C;&#x5F00;&#x59CB;&#x81EA;&#x52A8;&#x6267;&#x884C;</li>
<li>ng &#x81EA;&#x52A8;&#x627E;&#x5230;&#x7F51;&#x9875;&#x4E2D;&#x5177;&#x6709; ng-app &#x5C5E;&#x6027;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x7136;&#x540E;&#x5F00;&#x59CB;&#x89E3;&#x6790;&#x8BE5;&#x5143;&#x7D20;&#x5185;&#x90E8;&#x6240;&#x6709;&#x80FD;&#x88AB; ng &#x6240;&#x8BC6;&#x522B;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4; ng-app &#x5728;&#x8FD9;&#x91CC;&#x5C31;&#x5145;&#x5F53;&#x4E86; ng &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x542F;&#x52A8;&#x7684;&#x5165;&#x53E3;&#x6807;&#x8BC6;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x662F; ng &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x7BA1;&#x7406;&#x8FB9;&#x754C;</li>
<li>ng &#x627E;&#x5230;&#x5165;&#x53E3;&#x6807;&#x8BC6;&#x4E4B;&#x540E;&#xFF0C;&#x5F00;&#x59CB;&#x89E3;&#x6790;&#x8BE5;&#x5165;&#x53E3;&#x6807;&#x8BC6;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x81EA;&#x5DF1;&#x80FD;&#x8BC6;&#x522B;&#x7684;&#x5185;&#x5BB9;</li>
</ol>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x4E86;&#x4E00;&#x4E2A; <code>\{\{\}\}</code> &#x8868;&#x8FBE;&#x5F0F;&#xFF0C;<code>\{\{\}\}</code> &#x5728; ng &#x4E2D;&#x88AB;&#x79F0;&#x4F5C;&#x82B1;&#x62EC;&#x53F7;&#x63D2;&#x503C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<h2 id="AngularJS-&#x8868;&#x8FBE;&#x5F0F;"><a href="#AngularJS-&#x8868;&#x8FBE;&#x5F0F;" class="headerlink" title="AngularJS &#x8868;&#x8FBE;&#x5F0F;"></a>AngularJS &#x8868;&#x8FBE;&#x5F0F;</h2><ul>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x5199;&#x5728;&#x53CC;&#x5927;&#x62EC;&#x53F7;&#x5185;&#xFF1A;<code>\{\{ expression \}\}</code></li>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x628A;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x5230; HTML&#xFF0C;&#x4E0E; <code>ng-bind</code> &#x6307;&#x4EE4;&#x57FA;&#x672C;&#x4E00;&#x81F4;</li>
<li>AngularJS &#x5C06;&#x5728;&#x8868;&#x8FBE;&#x5F0F;&#x4E66;&#x5199;&#x7684;&#x4F4D;&#x7F6E;&#x201D;&#x8F93;&#x51FA;&#x201D;&#x6570;&#x636E;<ul>
<li>&#x6570;&#x5B57;</li>
<li>&#x5B57;&#x7B26;&#x4E32;</li>
<li>&#x5BF9;&#x8C61;</li>
<li>&#x6570;&#x7EC4;</li>
</ul>
</li>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F; &#x5F88;&#x50CF; JavaScript &#x8868;&#x8FBE;&#x5F0F;&#xFF1A;&#x5B83;&#x4EEC;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x64CD;&#x4F5C;&#x7B26;&#x548C;&#x53D8;&#x91CF;<ul>
<li>&#x4E0E; JavaScript &#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x540C;&#xFF0C;AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x5199;&#x5728; HTML &#x4E2D;</li>
<li>&#x4E0E; JavaScript &#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x540C;&#xFF0C;AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x652F;&#x6301;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#xFF0C;&#x5FAA;&#x73AF;&#x53CA;&#x5F02;&#x5E38;</li>
<li>&#x4E0E; JavaScript &#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x540C;&#xFF0C;AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x652F;&#x6301;&#x8FC7;&#x6EE4;&#x5668;</li>
</ul>
</li>
</ul>
<p>&#x5728;AngularJS&#x4E2D;&#xFF0C;&#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x4E00;&#x79CD;&#x7C7B;&#x4F3C;&#x4E8E;&#x6A21;&#x677F;&#x5F15;&#x64CE;&#x7684;&#x8BED;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x4E66;&#x5199;&#x7684;&#x4F4D;&#x7F6E; &#x201C;&#x8F93;&#x51FA;&#x201D; &#x6570;&#x636E;&#x3002;</p>
<h3 id="&#x57FA;&#x672C;&#x4F7F;&#x7528;"><a href="#&#x57FA;&#x672C;&#x4F7F;&#x7528;" class="headerlink" title="&#x57FA;&#x672C;&#x4F7F;&#x7528;"></a>&#x57FA;&#x672C;&#x4F7F;&#x7528;</h3><ul>
<li>&#x8868;&#x8FBE;&#x5F0F;&#x5199;&#x5728;&#x53CC;&#x5927;&#x62EC;&#x53F7;&#x5185;&#xFF1A;<code>\{\{ expression \}\}</code></li>
<li>&#x8868;&#x8FBE;&#x5F0F; &#x5F88;&#x50CF; JavaScript &#x8868;&#x8FBE;&#x5F0F;</li>
<li>&#x5B83;&#x4EEC;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x6587;&#x5B57;&#x3001;&#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x53D8;&#x91CF;</li>
<li>&#x5982; <code>\{\{ 5 + 5 \}\}</code> &#x6216; <code>\{\{ firstName + lastName \}\}</code></li>
</ul>
<h3 id="&#x652F;&#x6301;&#x7684;&#x7C7B;&#x578B;&#x53CA;&#x64CD;&#x4F5C;&#x7B26;"><a href="#&#x652F;&#x6301;&#x7684;&#x7C7B;&#x578B;&#x53CA;&#x64CD;&#x4F5C;&#x7B26;" class="headerlink" title="&#x652F;&#x6301;&#x7684;&#x7C7B;&#x578B;&#x53CA;&#x64CD;&#x4F5C;&#x7B26;"></a>&#x652F;&#x6301;&#x7684;&#x7C7B;&#x578B;&#x53CA;&#x64CD;&#x4F5C;&#x7B26;</h3><ul>
<li>&#x6570;&#x5B57;</li>
<li>&#x5B57;&#x7B26;&#x4E32;</li>
<li>&#x5BF9;&#x8C61;</li>
<li>&#x6570;&#x7EC4;</li>
<li><code>+ - * /</code></li>
<li>&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;</li>
<li>&#x77ED;&#x8DEF;&#x8FD0;&#x7B97;&#x7B26;</li>
</ul>
<p>&#x5982;&#x679C;&#x662F; null &#x6216; undefined &#xFF0C;&#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<h3 id="Angular-&#x8868;&#x8FBE;&#x5F0F;&#x4E0E;-JavaScript-&#x533A;&#x522B;&#xFF1A;"><a href="#Angular-&#x8868;&#x8FBE;&#x5F0F;&#x4E0E;-JavaScript-&#x533A;&#x522B;&#xFF1A;" class="headerlink" title="Angular &#x8868;&#x8FBE;&#x5F0F;&#x4E0E; JavaScript &#x533A;&#x522B;&#xFF1A;"></a>Angular &#x8868;&#x8FBE;&#x5F0F;&#x4E0E; JavaScript &#x533A;&#x522B;&#xFF1A;</h3><p>&#x76F8;&#x540C;&#x70B9;&#xFF1A;</p>
<p>&#x90FD;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5B57;&#x6BCD;&#x3001;&#x64CD;&#x4F5C;&#x7B26;&#x3001;&#x53D8;&#x91CF;</p>
<p>&#x4E0D;&#x540C;&#x70B9;&#xFF1A;</p>
<ul>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x5199;&#x5728; HTML &#x4E2D;</li>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x4E0D;&#x652F;&#x6301;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#xFF0C;&#x5FAA;&#x73AF;&#x53CA;&#x5F02;&#x5E38;</li>
<li>AngularJS &#x8868;&#x8FBE;&#x5F0F;&#x652F;&#x6301;&#x8FC7;&#x6EE4;&#x5668;</li>
</ul>
<h3 id="&#x89E3;&#x51B3;&#x8868;&#x8FBE;&#x5F0F;&#x95EA;&#x70C1;&#x7684;&#x95EE;&#x9898;"><a href="#&#x89E3;&#x51B3;&#x8868;&#x8FBE;&#x5F0F;&#x95EA;&#x70C1;&#x7684;&#x95EE;&#x9898;" class="headerlink" title="&#x89E3;&#x51B3;&#x8868;&#x8FBE;&#x5F0F;&#x95EA;&#x70C1;&#x7684;&#x95EE;&#x9898;"></a>&#x89E3;&#x51B3;&#x8868;&#x8FBE;&#x5F0F;&#x95EA;&#x70C1;&#x7684;&#x95EE;&#x9898;</h3><p>ng &#x9ED8;&#x8BA4;&#x662F;&#x5728; document onload &#x7684;&#x65F6;&#x5019;&#x5F00;&#x59CB;&#x89E3;&#x6790;&#x6267;&#x884C;&#xFF0C;ng &#x5728;&#x542F;&#x52A8;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x81EA;&#x52A8;&#x5411; head &#x4E2D;&#x63D2;&#x5165;&#x4E00;&#x4E2A; style &#x6837;&#x5F0F;&#x3002;</p>
<ul>
<li>ng-cloak</li>
<li>ng-bind</li>
</ul>
<blockquote>
<p>&#x8BE6;&#x7EC6;&#x8BF4;&#x660E;&#xFF1A;</p>
</blockquote>
<p>&#x89E3;&#x51B3;&#x8868;&#x8FBE;&#x5F0F;&#x95EA;&#x70C1;&#x65B9;&#x5F0F;&#x6709;&#x4E24;&#x79CD;&#xFF1A;</p>
<p>&#x7B2C;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;</p>
<blockquote>
<p>&#x5C06; ng &#x811A;&#x672C;&#x5F15;&#x5165;&#x5230; head &#x4E2D;&#xFF0C;ng &#x5B98;&#x65B9;&#x63A8;&#x8350;&#x5C06; ng &#x811A;&#x672C;&#x5F15;&#x5165;&#x6700;&#x4E0A;&#x9762;&#xFF1B;<br>&#x5728;&#x6240;&#x6709;&#x4F7F;&#x7528;&#x4E86;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x5916;&#x90E8;&#x7684;&#x8282;&#x70B9;&#x4E0A;&#x52A0;&#x4E00;&#x4E2A;&#x5C5E;&#x6027; ng-cloak&#xFF1B;<br>&#x5F53;&#x52A0;&#x4E0A; ng-cloak &#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#xFF0C;ng &#x4E0D;&#x4F1A;&#x7B49;&#x5F85; DOM onload &#x6267;&#x884C;&#x7ED3;&#x675F;&#x5C31;&#x4F1A;&#x5148;&#x5728;&#x52A0;&#x4E86; ng-cloak &#x7684;&#x5730;&#x65B9;&#x4F5C;&#x7528;&#x4E00;&#x4E2A;&#x6837;&#x5F0F; display: none !important&#xFF1B;<br>&#x5F53; ng &#x89E3;&#x6790;&#x5B8C;&#x6BD5;&#x4E4B;&#x540E;&#xFF0C;ng-cloak&#xFF08;&#x6837;&#x5F0F;&#xFF09; &#x88AB;&#x81EA;&#x52A8;&#x79FB;&#x9664;&#x3002;</p>
</blockquote>
<p>&#x7B2C;&#x4E8C;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;</p>
<blockquote>
<p>&#x5728;&#x6240;&#x6709;&#x4F7F;&#x7528;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x5730;&#x65B9;&#x90FD;&#x901A;&#x8FC7; ng-bind &#x6307;&#x4EE4;&#x6765;&#x4EE3;&#x66FF;&#xFF1B;<br>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4F7F;&#x7528;&#x4E86; ng-bind &#x53EF;&#x4EE5;&#x5B8C;&#x5168;&#x66FF;&#x4EE3;&#x8868;&#x8FBE;&#x5F0F;&#xFF1B;<br>&#x7528;&#x4E86;&#x5B83;&#x5C31;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x5C06; ng&#x811A;&#x672C;&#x5F15;&#x5165;&#x5E95;&#x90E8;&#x4E5F;&#x4E0D;&#x95EA;&#x70C1;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
</blockquote>
<h2 id="AngularJS-&#x6307;&#x4EE4;"><a href="#AngularJS-&#x6307;&#x4EE4;" class="headerlink" title="AngularJS &#x6307;&#x4EE4;"></a>AngularJS &#x6307;&#x4EE4;</h2><p>AngularJS &#x6307;&#x4EE4;&#x662F;&#x4EE5; <code>ng-</code> &#x4F5C;&#x4E3A;&#x524D;&#x7F00;&#x7684; HTML &#x5C5E;&#x6027;&#xFF0C;AngularJS &#x901A;&#x8FC7;&#x5185;&#x7F6E;&#x7684;&#x6307;&#x4EE4;&#x6765;&#x4E3A;&#x5E94;&#x7528;&#x6DFB;&#x52A0;&#x529F;&#x80FD;&#xFF0C;AngularJS &#x540C;&#x65F6;&#x5141;&#x8BB8;&#x81EA;&#x5B9A;&#x4E49;&#x6307;&#x4EE4;&#xFF0C;&#x4ECE;&#x800C;&#x6784;&#x5EFA;&#x66F4;&#x52A0;&#x8D85;&#x52A8;&#x611F;&#x7684; HTML&#x3002;</p>
<p>HTML5 &#x5141;&#x8BB8;&#x6269;&#x5C55;&#x7684;&#xFF08;&#x81EA;&#x5236;&#x7684;&#xFF09;&#x5C5E;&#x6027;&#xFF0C;&#x4EE5; <code>data-</code> &#x5F00;&#x5934;&#x3002;AngularJS &#x5C5E;&#x6027;&#x4EE5; ng- &#x5F00;&#x5934;&#xFF0C;&#x4F46;&#x662F;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>data-ng-</code> &#x6765;&#x8BA9;&#x7F51;&#x9875;&#x5BF9; HTML5 &#x6709;&#x6548;&#x3002;</p>
<h2 id="&#x6307;&#x4EE4;&#x7684;&#x4F7F;&#x7528;&#x5F62;&#x5F0F;"><a href="#&#x6307;&#x4EE4;&#x7684;&#x4F7F;&#x7528;&#x5F62;&#x5F0F;" class="headerlink" title="&#x6307;&#x4EE4;&#x7684;&#x4F7F;&#x7528;&#x5F62;&#x5F0F;"></a>&#x6307;&#x4EE4;&#x7684;&#x4F7F;&#x7528;&#x5F62;&#x5F0F;</h2><ul>
<li>ng-xxx &#x7684;&#x5C5E;&#x6027;&#x672C;&#x8EAB;&#x5E76;&#x4E0D;&#x662F;&#x6807;&#x51C6;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x5C5E;&#x6027;</li>
<li>&#x5F88;&#x591A;&#x60C5;&#x51B5;&#x4E0B;&#x65E0;&#x6CD5;&#x901A;&#x8FC7;&#x8BED;&#x6CD5;&#x6821;&#x9A8C;</li>
<li>HTML5 &#x5141;&#x8BB8;&#x6269;&#x5C55;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4EE5; <code>data-</code> &#x5F00;&#x5934;</li>
<li>&#x5728; ng &#x4E2D;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>data-ng-</code> &#x4F5C;&#x4E3A;&#x524D;&#x7F00;&#x6765;&#x8BA9;&#x7F51;&#x9875;&#x5BF9; HTML5 &#x6709;&#x6548;</li>
<li>&#x4E8C;&#x8005;&#x6548;&#x679C;&#x76F8;&#x540C;</li>
</ul>
<h3 id="&#x5185;&#x7F6E;&#x6307;&#x4EE4;"><a href="#&#x5185;&#x7F6E;&#x6307;&#x4EE4;" class="headerlink" title="&#x5185;&#x7F6E;&#x6307;&#x4EE4;"></a>&#x5185;&#x7F6E;&#x6307;&#x4EE4;</h3><p>AngularJS &#x5185;&#x7F6E;&#x4E86;&#x5F88;&#x591A;&#x6307;&#x4EE4;&#xFF0C;&#x7528;&#x6765;&#x589E;&#x5F3A; HTML&#xFF0C;&#x4EE5;&#x4E0B;&#x662F;&#x4E00;&#x4E9B;&#x5E38;&#x7528;&#x5185;&#x7F6E;&#x6307;&#x4EE4;&#x7684;&#x4ECB;&#x7ECD;&#x3002;</p>
<h4 id="ngApp"><a href="#ngApp" class="headerlink" title="ngApp"></a>ngApp</h4><ul>
<li>ng-app</li>
</ul>
<h4 id="ngController"><a href="#ngController" class="headerlink" title="ngController"></a>ngController</h4><h4 id="ngInit"><a href="#ngInit" class="headerlink" title="ngInit"></a>ngInit</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>ng - &#x53CC;&#x5411;&#x7ED1;&#x5B9A;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span> <span class="attr">ng-init</span>=<span class="string">&quot;name=&apos;World&apos;&quot;</span>&gt;</span></div><div class="line">  <span class="comment">&lt;!-- input &#x7684; value &#x548C;&#x6A21;&#x578B;&#x4E2D;&#x7684; name &#x5EFA;&#x7ACB;&#x53CC;&#x5411;&#x7ED1;&#x5B9A;&#x5173;&#x7CFB; --&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;name&quot;</span>&gt;</span></div><div class="line">  <span class="comment">&lt;!-- </span></div><div class="line">    input &#x7684; value &#x548C;&#x6A21;&#x578B;&#x4E2D;&#x7684; age &#x5EFA;&#x7ACB;&#x53CC;&#x5411;&#x7ED1;&#x5B9A;&#x5173;&#x7CFB; </div><div class="line">    age &#x4E0D;&#x4E00;&#x5B9A;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#xFF0C;&#x5F53;&#x4F60;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x53BB;&#x6A21;&#x578B;&#x4E2D;&#x521D;&#x59CB;&#x5316; age&#xFF0C;&#x53EA;&#x4E0D;&#x8FC7;&#x6CA1;&#x6709;&#x503C;&#x800C;&#x5DF2;</div><div class="line">    &#x5982;&#x679C;&#x60F3;&#x8981;&#x7ED9; age &#x521D;&#x59CB;&#x5316;&#x6570;&#x636E;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; ng-init &#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x7ED9; age &#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x503C;</div><div class="line">    ng-init &#x4EE5;&#x540E;&#x4E5F;&#x4F1A;&#x5F88;&#x5C11;&#x9002;&#x5E94;&#xFF0C;&#x8FD9;&#x91CC;&#x662F;&#x4E3A;&#x4E86;&#x6848;&#x4F8B;&#x6F14;&#x793A;</div><div class="line">    --&gt;</div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;age&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">h1</span>&gt;</span>Hello {{name}}<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">h1</span>&gt;</span>&#x5E74;&#x9F84; {{age}}<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<h4 id="ngBind"><a href="#ngBind" class="headerlink" title="ngBind"></a>ngBind</h4><ul>
<li>ng-bind</li>
<li>ng-non-bindable</li>
</ul>
<h4 id="ngBindHtml"><a href="#ngBindHtml" class="headerlink" title="ngBindHtml"></a>ngBindHtml</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">h1</span> <span class="attr">ng-bind</span>=<span class="string">&quot;title&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">h1</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-bind-html</span>=<span class="string">&quot;content&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../node_modules/angular-sanitize/angular-sanitize.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    <span class="comment">// &#x5982;&#x679C;&#x60F3;&#x8981;&#x7ED1;&#x5B9A; HTML &#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;</span></div><div class="line">    <span class="comment">//    1. npm install --save angular-sanitize</span></div><div class="line">    <span class="comment">//    2. &#x5728;&#x4F7F;&#x7528;&#x8BE5;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6240;&#x5C5E;&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x52A0;&#x8F7D; ngSanitize &#x6A21;&#x5757;&#x5373;&#x53EF;&#x751F;&#x6548;</span></div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>, [<span class="string">&apos;ngSanitize&apos;</span>]).controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.title = <span class="string">&apos;&#x4F7F;&#x7528;ngSanitize &#x6A21;&#x5757;&#x7ED1;&#x5B9A; HTML &#x5B57;&#x7B26;&#x4E32;&apos;</span></div><div class="line">      $scope.content = <span class="string">&apos;&lt;script&gt;window.alert(&quot;hello&quot;)&lt;\/script&gt;&lt;p&gt;&#x4F5C;&#x8005;&#xFF1A;xxx&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Hiraku&lt;/strong&gt;&#x5982;&#x4F55;&#x7ED1;&#x5B9A;&lt;/p&gt;&apos;</span></div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div></pre></td></tr></table></figure>
<h4 id="ngRepeat"><a href="#ngRepeat" class="headerlink" title="ngRepeat"></a>ngRepeat</h4><ul>
<li>ng-repeat</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">table</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">thead</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">tr</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x7F16;&#x53F7;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x59D3;&#x540D;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x5E74;&#x9F84;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x6027;&#x522B;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">thead</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">tbody</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">tr</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;friend in friends&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{$index+1}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.name}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.age}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.gender}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">tbody</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">table</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">ul</span>&gt;</span></div><div class="line">    <span class="comment">&lt;!-- &#x5229;&#x7528; track by $index &#x89E3;&#x51B3;&#x91CD;&#x590D;&#x9879;&#x62A5;&#x9519;&#x95EE;&#x9898; --&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;fruit in fruits track by $index&quot;</span>&gt;</span>{{fruit}}<span class="tag">&lt;/<span class="name">li</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../code/js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>, []).controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      <span class="comment">/* beautify ignore:start */</span></div><div class="line">      $scope.friends = [{<span class="attr">name</span>:<span class="string">&apos;John&apos;</span>, <span class="attr">age</span>:<span class="number">25</span>, <span class="attr">gender</span>:<span class="string">&apos;boy&apos;</span>},{<span class="attr">name</span>:<span class="string">&apos;John&apos;</span>, <span class="attr">age</span>:<span class="number">25</span>, <span class="attr">gender</span>:<span class="string">&apos;boy&apos;</span>}, {<span class="attr">name</span>:<span class="string">&apos;Jessie&apos;</span>, <span class="attr">age</span>:<span class="number">30</span>, <span class="attr">gender</span>:<span class="string">&apos;girl&apos;</span>}];</div><div class="line">      <span class="comment">// ng-repeat &#x5728;&#x904D;&#x5386;&#x666E;&#x901A;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x76F8;&#x540C;&#x7684;&#x503C;&#xFF0C;&#x4F1A;&#x62A5;&#x9519;&#xFF1B;&#x5728;&#x4F7F;&#x7528; ng-repeat &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x90FD;&#x6700;&#x597D;&#x52A0;&#x4E0A; track by $index &#x6765;&#x907F;&#x514D;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;</span></div><div class="line">      $scope.fruits = [<span class="string">&apos;&#x1F34E;&apos;</span>,<span class="string">&apos;&#x1F34E;&apos;</span>, <span class="string">&apos;&#x1F34C;&apos;</span>, <span class="string">&apos;&#x1F350;&apos;</span>, <span class="string">&apos;&#x1F349;&apos;</span>];</div><div class="line">      <span class="comment">/* beautify ignore:end */</span></div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div></pre></td></tr></table></figure>
<h4 id="&#x89E3;&#x51B3;&#x91CD;&#x590D;&#x9879;&#x62A5;&#x9519;&#x95EE;&#x9898;"><a href="#&#x89E3;&#x51B3;&#x91CD;&#x590D;&#x9879;&#x62A5;&#x9519;&#x95EE;&#x9898;" class="headerlink" title="&#x89E3;&#x51B3;&#x91CD;&#x590D;&#x9879;&#x62A5;&#x9519;&#x95EE;&#x9898;"></a>&#x89E3;&#x51B3;&#x91CD;&#x590D;&#x9879;&#x62A5;&#x9519;&#x95EE;&#x9898;</h4><h4 id="ngClass"><a href="#ngClass" class="headerlink" title="ngClass"></a>ngClass</h4><ul>
<li>ng-class</li>
<li>ng-class-even</li>
<li>ng-class-odd</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">  &#x70B9;&#x51FB;&#x5207;&#x6362;&#x5B57;&#x4F53;&#x989C;&#x8272;&#xFF1A;<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;isRed&quot;</span>&gt;</span></div><div class="line">  &#x70B9;&#x51FB;&#x5207;&#x6362;&#x80CC;&#x666F;&#x8272;&#xFF1A;<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;isGreen&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">ng-class</span>=<span class="string">&quot;{red: isRed, green: isGreen}&quot;</span>&gt;</span>ng-class &#x7684;&#x4F7F;&#x7528;<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">ul</span>&gt;</span><span class="tag">&lt;<span class="name">li</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;friend in friends&quot;</span> <span class="attr">ng-class-odd</span>=<span class="string">&quot;&apos;bgRed&apos;&quot;</span> <span class="attr">ng-class-even</span>=<span class="string">&quot;{bgGreen: isGreen}&quot;</span>&gt;</span></div><div class="line">    {{friend.name}} - {{friend.age}} - {{friend.gender}}</div><div class="line">  <span class="tag">&lt;/<span class="name">li</span>&gt;</span><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../code/js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">  angular.module(<span class="string">&apos;DemoApp&apos;</span>, []).controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">    $scope.friends = [{<span class="attr">name</span>:<span class="string">&apos;John&apos;</span>, <span class="attr">age</span>:<span class="number">25</span>, <span class="attr">gender</span>:<span class="string">&apos;boy&apos;</span>}, {<span class="attr">name</span>:<span class="string">&apos;John&apos;</span>, <span class="attr">age</span>:<span class="number">25</span>, <span class="attr">gender</span>:<span class="string">&apos;boy&apos;</span>}, {<span class="attr">name</span>:<span class="string">&apos;Jessie&apos;</span>, <span class="attr">age</span>:<span class="number">30</span>, <span class="attr">gender</span>:<span class="string">&apos;girl&apos;</span>}];</div><div class="line">  }]);</div><div class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div></pre></td></tr></table></figure>
<h4 id="ng-cloak"><a href="#ng-cloak" class="headerlink" title="ng-cloak"></a>ng-cloak</h4><h4 id="ng-hide-show-if-switch"><a href="#ng-hide-show-if-switch" class="headerlink" title="ng-hide-show-if-switch"></a>ng-hide-show-if-switch</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;loading&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">img</span> <span class="attr">ng-show</span>=<span class="string">&quot;loading&quot;</span> <span class="attr">src</span>=<span class="string">&quot;img/loading-green-3.gif&quot;</span> <span class="attr">alt</span>=<span class="string">&quot;&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">img</span> <span class="attr">ng-hide</span>=<span class="string">&quot;!loading&quot;</span> <span class="attr">src</span>=<span class="string">&quot;img/loading-green-3.gif&quot;</span> <span class="attr">alt</span>=<span class="string">&quot;&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">select</span> <span class="attr">ng-model</span>=<span class="string">&quot;selection&quot;</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;city in cities&quot;</span> <span class="attr">value</span>=<span class="string">&quot;{{city.id}}&quot;</span>&gt;</span>{{city.name}}<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">select</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-switch</span> <span class="attr">on</span>=<span class="string">&quot;selection&quot;</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-switch-when</span>=<span class="string">&quot;1&quot;</span>&gt;</span>&#x5317;&#x4EAC;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-switch-when</span>=<span class="string">&quot;2&quot;</span>&gt;</span>&#x4E0A;&#x6D77;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-switch-when</span>=<span class="string">&quot;3&quot;</span>&gt;</span>&#x5E7F;&#x5DDE;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">img</span> <span class="attr">ng-if</span>=<span class="string">&quot;loading&quot;</span> <span class="attr">src</span>=<span class="string">&quot;./img/loading-green-3.gif&quot;</span> <span class="attr">alt</span>=<span class="string">&quot;&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../code/js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>, []).controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="string">&apos;$timeout&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope, $timeout</span>) </span>{</div><div class="line">      $scope.loading = <span class="literal">true</span>;</div><div class="line">      setTimeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</div><div class="line">          <span class="comment">// &#x5982;&#x679C;&#x5728;&#x666E;&#x901A;&#x7684;&#x5B9A;&#x65F6;&#x5668;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;&#x4E86; $scope &#x89C6;&#x56FE;&#x6A21;&#x578B;&#x6210;&#x5458;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x901A;&#x8FC7; $scope.$apply() &#x624B;&#x52A8;&#x5237;&#x65B0;&#x89C6;&#x56FE;&#x6A21;&#x578B;&#x624D;&#x884C;</span></div><div class="line">          $scope.loading = <span class="literal">false</span>;</div><div class="line">          $scope.$apply();</div><div class="line">        }, <span class="number">10000</span>)</div><div class="line">        <span class="comment">// $timeout(function () {</span></div><div class="line">        <span class="comment">//   $scope.loading = false;</span></div><div class="line">        <span class="comment">// }, 2000);</span></div><div class="line">      $scope.cities = [{<span class="attr">id</span>: <span class="number">1</span>, <span class="attr">name</span>: <span class="string">&apos;&#x5317;&#x4EAC;&apos;</span>}, {<span class="attr">id</span>: <span class="number">2</span>, <span class="attr">name</span>: <span class="string">&apos;&#x4E0A;&#x6D77;&apos;</span>}, {<span class="attr">id</span>: <span class="number">3</span>, <span class="attr">name</span>: <span class="string">&apos;&#x5E7F;&#x5DDE;&apos;</span>}];</div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div></pre></td></tr></table></figure>
<blockquote>
<p>ng-if-hide-show &#x7684;&#x533A;&#x522B;</p>
</blockquote>
<ul>
<li>ng-if &#x662F;&#x76F4;&#x63A5;&#x5C31;&#x4E0D;&#x6E32;&#x67D3;&#x8FD9;&#x4E2A; DOM &#x4E86;<ul>
<li>&#x5F53;&#x4E3A; true &#x7684;&#x65F6;&#x5019;&#x76F4;&#x63A5;&#x6E32;&#x67D3;</li>
<li>&#x5F53;&#x4E3A; false &#x7684;&#x65F6;&#x5019;&#x76F4;&#x63A5;&#x79FB;&#x9664;&#x8BE5;&#x5143;&#x7D20;</li>
</ul>
</li>
<li>ng-hide/ng-show<ul>
<li>&#x4E24;&#x8005;&#x65E0;&#x8BBA;&#x662F; true &#x8FD8;&#x662F; false &#x5143;&#x7D20;&#x90FD;&#x5728;&#xFF0C;&#x662F;&#x901A;&#x8FC7;&#x6837;&#x5F0F;&#x6765;&#x63A7;&#x5236;&#x7684;</li>
</ul>
</li>
</ul>
<h4 id="ng-src"><a href="#ng-src" class="headerlink" title="ng-src"></a>ng-src</h4><p>&#x6240;&#x6709;&#x9700;&#x8981;&#x52A8;&#x6001;&#x6307;&#x5B9A; src &#x7684;&#x5730;&#x65B9;&#x90FD;&#x901A;&#x8FC7; ng-src &#x6765;&#x66FF;&#x6362;&#xFF0C;&#x5426;&#x5219;&#x6D4F;&#x89C8;&#x5668;&#x4F1A;&#x771F;&#x7684;&#x5BF9;&#x8FD9;&#x4E2A; src &#x53D1;&#x8D77;&#x8BF7;&#x6C42;</p>
<h4 id="&#x5176;&#x5B83;&#x5E38;&#x7528;&#x6307;&#x4EE4;"><a href="#&#x5176;&#x5B83;&#x5E38;&#x7528;&#x6307;&#x4EE4;" class="headerlink" title="&#x5176;&#x5B83;&#x5E38;&#x7528;&#x6307;&#x4EE4;"></a>&#x5176;&#x5B83;&#x5E38;&#x7528;&#x6307;&#x4EE4;</h4><ul>
<li>ng-checked : &#x5355;&#x9009;/&#x590D;&#x9009;&#x662F;&#x5426;&#x9009;&#x4E2D;&#xFF0C;&#x53EA;&#x662F;&#x5355;&#x5411;&#x7ED1;&#x5B9A;&#x6570;&#x636E;</li>
<li>ng-disabled : &#x662F;&#x5426;&#x7981;&#x7528;</li>
<li>ng-readonly : &#x662F;&#x5426;&#x53EA;&#x8BFB;</li>
<li>ng-selected : &#x662F;&#x5426;&#x9009;&#x4E2D;&#xFF0C;&#x53EA;&#x662F;&#x5355;&#x5411;&#x6570;&#x636E;&#x7ED1;&#x5B9A;</li>
</ul>
<h4 id="&#x4E8B;&#x4EF6;&#x578B;&#x6307;&#x4EE4;"><a href="#&#x4E8B;&#x4EF6;&#x578B;&#x6307;&#x4EE4;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x578B;&#x6307;&#x4EE4;"></a>&#x4E8B;&#x4EF6;&#x578B;&#x6307;&#x4EE4;</h4><ul>
<li>ng-click &#xFF1A;&#x9F20;&#x6807;&#x5355;&#x51FB;</li>
<li>ng-blur &#xFF1A;&#x5931;&#x53BB;&#x7126;&#x70B9;</li>
<li>ng-focus &#xFF1A;&#x5F97;&#x5230;&#x7126;&#x70B9;</li>
<li>ng-change &#xFF1A;&#x53D1;&#x751F;&#x6539;&#x53D8;</li>
<li>ng-copy &#xFF1A;&#x62F7;&#x8D1D;&#x5B8C;&#x6210;</li>
<li>ng-dblclick &#xFF1A;&#x9F20;&#x6807;&#x53CC;&#x51FB;</li>
<li>ng-submit&#xFF1A;&#x8868;&#x5355;&#x63D0;&#x4EA4;</li>
<li>ng-copy</li>
<li>ng-cut</li>
<li>ng-paste</li>
<li>ng-keydown</li>
<li>ng-keyup</li>
<li>ng-mousedown</li>
<li>ng-mouseenter</li>
<li>ng-mouseleave</li>
<li>ng-mouseover</li>
<li>ng-mouseup</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>ng - &#x8D2D;&#x7269;&#x8F66;&#x8BA1;&#x4EF7;&#x5668;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span> <span class="attr">ng-init</span>=<span class="string">&quot;price=9.9; count=6;&quot;</span>&gt;</span></div><div class="line">  &#x5355;&#x4EF7;&#xFF1A;</div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;number&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;price&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">br</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">br</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">button</span> <span class="attr">ng-click</span>=<span class="string">&quot;count = count - 1 &lt;= 0 ? 0 : count - 1&quot;</span>&gt;</span>-<span class="tag">&lt;/<span class="name">button</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">span</span>&gt;</span>{{count}}<span class="tag">&lt;/<span class="name">span</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">button</span> <span class="attr">ng-click</span>=<span class="string">&quot;count = count + 1&quot;</span>&gt;</span>+<span class="tag">&lt;/<span class="name">button</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">br</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{price * count | number:2}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{&apos;abc&apos; | uppercase}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{&apos;ABC&apos; | lowercase}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<blockquote>
<p>ng &#x4E2D;&#x4E5F;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x5355;&#x5411;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x7684;&#x6307;&#x4EE4;</p>
</blockquote>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x6A21;&#x578B;&#x83B7;&#x53D6;&#x5230;&#x6570;&#x636E;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x6539;&#x53D8;&#x5143;&#x7D20;&#x503C;&#x800C;&#x5F71;&#x54CD;&#x89C6;&#x56FE;&#x6A21;&#x578B;&#x6570;&#x636E;&#x3002;</p>
<h2 id="&#x89C6;&#x56FE;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF1A;-scope"><a href="#&#x89C6;&#x56FE;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF1A;-scope" class="headerlink" title="&#x89C6;&#x56FE;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF1A;$scope"></a>&#x89C6;&#x56FE;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF1A;$scope</h2><ul>
<li>$scope &#x662F;&#x7528;&#x6765;&#x89C6;&#x56FE;&#x548C;&#x6570;&#x636E;&#x4E4B;&#x95F4;&#x7684;&#x80F6;&#x6C34;&#x3001;&#x7C98;&#x5408;&#x5242;</li>
<li>&#x89C6;&#x56FE;&#x548C;&#x63A7;&#x5236;&#x5668;&#x4E4B;&#x95F4;&#x7684;&#x6570;&#x636E;&#x6865;&#x6881;</li>
<li>&#x7528;&#x4E8E;&#x5728;&#x89C6;&#x56FE;&#x548C;&#x63A7;&#x5236;&#x5668;&#x4E4B;&#x95F4;&#x4F20;&#x9012;&#x6570;&#x636E;</li>
<li>&#x7528;&#x6765;&#x66B4;&#x9732;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF08;&#x6570;&#x636E;&#x3001;&#x884C;&#x4E3A;&#xFF09;</li>
<li>&#x76D1;&#x89C6;&#x6A21;&#x578B;&#x6570;&#x636E;&#x7684;&#x53D8;&#x5316;&#xFF0C;&#x505A;&#x51FA;&#x76F8;&#x5E94;&#x7684;&#x52A8;&#x4F5C; <code>$scope.$watch</code></li>
</ul>
<h3 id="&#x5982;&#x4F55;&#x8BBE;&#x8BA1;-scope"><a href="#&#x5982;&#x4F55;&#x8BBE;&#x8BA1;-scope" class="headerlink" title="&#x5982;&#x4F55;&#x8BBE;&#x8BA1; $scope"></a>&#x5982;&#x4F55;&#x8BBE;&#x8BA1; $scope</h3><p>&#x6839;&#x636E;&#x539F;&#x578B;&#x62BD;&#x8C61;&#x6570;&#x636E;&#x548C;&#x884C;&#x4E3A;&#xFF1A;</p>
<ul>
<li>&#x6570;&#x636E;</li>
<li>&#x884C;&#x4E3A;</li>
</ul>
<h3 id="ViewModel"><a href="#ViewModel" class="headerlink" title="ViewModel"></a>ViewModel</h3><p>ng &#x5B98;&#x65B9;&#x628A;&#x81EA;&#x5DF1;&#x5B9A;&#x4E49;&#x4E3A;&#x4E00;&#x4E2A; MVC &#x6846;&#x67B6;&#x3002;&#x5F88;&#x591A;&#x5F00;&#x53D1;&#x4F7F;&#x7528;&#x8005;&#x628A;&#x5B83;&#x79F0;&#x4E4B;&#x4E3A; MVVM &#x6846;&#x67B6;&#x3002;</p>
<ul>
<li>$scope &#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F; MVVM &#x4E2D;&#x6240;&#x8C13;&#x7684; VM&#xFF08;&#x89C6;&#x56FE;&#x6A21;&#x578B;&#xFF09;</li>
<li>&#x6B63;&#x5F0F;&#x56E0;&#x4E3A; $scope &#x5728; ng &#x4E2D;&#x5927;&#x91CF;&#x4F7F;&#x7528;&#x751A;&#x81F3;&#x76D6;&#x8FC7;&#x4E86; c &#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x6240;&#x4EE5;&#x5F88;&#x591A;&#x4EBA;&#x628A; ng &#x79F0;&#x4E4B;&#x4E3A; mvvm &#x6846;&#x67B6;</li>
</ul>
<h3 id="&#x6570;&#x636E;&#x6A21;&#x578B;&#x4F5C;&#x7528;&#x57DF;"><a href="#&#x6570;&#x636E;&#x6A21;&#x578B;&#x4F5C;&#x7528;&#x57DF;" class="headerlink" title="&#x6570;&#x636E;&#x6A21;&#x578B;&#x4F5C;&#x7528;&#x57DF;"></a>&#x6570;&#x636E;&#x6A21;&#x578B;&#x4F5C;&#x7528;&#x57DF;</h3><p>&#x628A;&#x6240;&#x6709;&#x7684;&#x6839;&#x636E;&#x89C6;&#x56FE;&#x62BD;&#x8C61;&#x51FA;&#x6765;&#x7684;&#x6210;&#x5458;&#x90FD;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;&#x4E2D;&#x4E5F;&#x5C31;&#x662F;&#x90FD;&#x653E;&#x5230;&#x5230;&#x4E00;&#x4E2A; $scoep &#x4E2D;&#xFF0C;&#x7EDD;&#x5BF9;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x592A;&#x5DEE;&#x4E86;&#xFF0C;&#x6BEB;&#x4E0D;&#x76F8;&#x5E72;&#x7684;&#x4E1A;&#x52A1;&#x90FD;&#x653E;&#x5230;&#x4E00;&#x8D77;&#x4E86;&#x3002;&#x6240;&#x4EE5;&#x5C31;&#x53EF;&#x4EE5;&#x4E3A;&#x4E0D;&#x540C;&#x7684;&#x4E1A;&#x52A1;&#x89C6;&#x56FE;&#x5212;&#x5206;&#x4E0D;&#x540C;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7684;&#x4E1A;&#x52A1;&#x5212;&#x5206;&#x4E0D;&#x540C;&#x7684;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;&#xFF0C;&#x5F97;&#x5230;&#x5BF9;&#x5E94;&#x7684; $scope &#x4F5C;&#x7528;&#x57DF;&#x6570;&#x636E;&#x6A21;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4F5C;&#x7528;&#x4E8E;&#x4E0D;&#x540C;&#x7684;&#x89C6;&#x56FE;&#x8BBF;&#x95EE;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x548C;&#x884C;&#x4E3A;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x53EF;&#x4EE5;&#x5D4C;&#x5957;&#xFF0C;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5D4C;&#x5957;&#x5173;&#x7CFB;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x6210;&#x5458;&#x3002;</p>
<p>ng 1.5 &#x4EE5;&#x4E0B;&#x7248;&#x672C;&#x4F7F;&#x7528;&#x89C6;&#x56FE;&#x6570;&#x636E;&#x6A21;&#x578B;&#x5B9A;&#x4E49;&#x8FC7;&#x7A0B;&#xFF1A;</p>
<ol>
<li>&#x5F15;&#x5305;</li>
<li>&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;<ul>
<li>&#x4E3B;&#x8981;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x628A;&#x903B;&#x8F91;&#x5199;&#x5230; JavaScript &#x4EE3;&#x7801;&#x4E2D;</li>
<li>&#x5176;&#x6B21;&#x662F;&#x4E3A;&#x4E86;&#x62FF;&#x5230;&#x90A3;&#x4E2A; $scope &#x6570;&#x636E;&#x6A21;&#x578B;&#x5BF9;&#x8C61;</li>
<li>&#x7136;&#x540E;&#x901A;&#x8FC7;&#x64CD;&#x4F5C; $scoep &#x6570;&#x636E;&#x6A21;&#x578B;&#xFF0C;&#x548C;&#x89C6;&#x56FE;&#x4F5C;&#x4EA4;&#x4E92;</li>
</ul>
</li>
<li>&#x6839;&#x636E;&#x89C6;&#x56FE;&#x66B4;&#x9732;&#x6A21;&#x578B;&#x6570;&#x636E;&#x6210;&#x5458;<ul>
<li>&#x7ED9; $scope &#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E9B;&#x6570;&#x636E;&#x6210;&#x5458;</li>
<li>&#x540C;&#x65F6;&#x66B4;&#x9732;&#x4E00;&#x4E9B;&#x884C;&#x4E3A;&#x51FD;&#x6570;</li>
</ul>
</li>
<li>&#x8BBE;&#x7F6E;&#x5165;&#x53E3;&#x6807;&#x8BC6; ng-app<ul>
<li>&#x8BBE;&#x7F6E;&#x63A7;&#x5236;&#x5668;<ul>
<li>&#x76EE;&#x7684;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x8BA9;&#x4F60;&#x7684;&#x89C6;&#x56FE;&#x548C; $scope &#x5EFA;&#x7ACB;&#x4F5C;&#x7528;&#x5173;&#x7CFB;</li>
<li>&#x901A;&#x8FC7;&#x64CD;&#x4F5C; $scope &#x548C;&#x89C6;&#x56FE;&#x4EA4;&#x4E92;</li>
<li>&#x628A;&#x4EE5;&#x524D;&#x5BF9; DOM &#x7684;&#x64CD;&#x4F5C;&#x53D8;&#x6210;&#x5BF9; $scope &#x6570;&#x636E;&#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x64CD;&#x4F5C;</li>
</ul>
</li>
</ul>
</li>
</ol>
<p><strong>&#x5728; ng 1.5 &#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x4E0D;&#x5141;&#x8BB8;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;&#x4E86;</strong></p>
<h2 id="&#x63A7;&#x5236;&#x5668;&#xFF1A;Controller"><a href="#&#x63A7;&#x5236;&#x5668;&#xFF1A;Controller" class="headerlink" title="&#x63A7;&#x5236;&#x5668;&#xFF1A;Controller"></a>&#x63A7;&#x5236;&#x5668;&#xFF1A;Controller</h2><ul>
<li>ng &#x4E2D;&#x7684;&#x63A7;&#x5236;&#x5668;&#x7528;&#x6765;&#x5BF9; scope &#x8FDB;&#x884C;&#x64CD;&#x4F5C;<ul>
<li>&#x5305;&#x62EC;&#x521D;&#x59CB;&#x5316;&#x6570;&#x636E;&#x548C;&#x5B9A;&#x4E49;&#x4E8B;&#x4EF6;&#x54CD;&#x5E94;&#x51FD;&#x6570;&#x7B49;</li>
</ul>
</li>
<li>ng &#x7528;&#x6765;&#x89E3;&#x8026;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x5C42;&#x548C;&#x89C6;&#x56FE;&#x5C42;&#x7684;&#x5173;&#x952E;</li>
<li>controller &#x64CD;&#x4F5C; scope&#xFF0C;View &#x5219;&#x5C55;&#x73B0; scope &#x7684;&#x5185;&#x5BB9;</li>
<li>&#x4F20;&#x7EDF;&#x524D;&#x7AEF;&#x7A0B;&#x5E8F;&#x4E2D;&#x5927;&#x91CF;&#x590D;&#x6742;&#x7684; DOM &#x64CD;&#x4F5C;&#x903B;&#x8F91;&#x90FD;&#x88AB;&#x8F6C;&#x53D8;&#x6210;&#x5BF9; scope &#x7684;&#x64CD;&#x4F5C;</li>
</ul>
<h3 id="&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x7684;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;"><a href="#&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x7684;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;" class="headerlink" title="&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x7684;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;"></a>&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x7684;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;</h3><p>&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x53EF;&#x4EE5;&#x6709;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x6CE8;&#x610F;&#x7B2C;&#x4E00;&#x79CD;&#x5DF2;&#x7ECF;&#x88AB;&#x6DD8;&#x6C70;&#x3002;</p>
<p>&#x7B2C;&#x4E00;&#x79CD;&#xFF1A;&#x4F20;&#x7EDF;&#x65B9;&#x5F0F;&#xFF0C;&#x4F7F;&#x7528;&#x5168;&#x5C40;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">DemoCtrl</span>(<span class="params">$scope</span>) </span>{</div><div class="line">  <span class="comment">// code here</span></div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x7B2C;&#x4E8C;&#x79CD;&#xFF1A;&#x6302;&#x8F7D;&#x5728;&#x67D0;&#x4E2A;&#x6A21;&#x5757;&#x4E0B;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">angular.module(<span class="string">&apos;DemoApp&apos;</span>, [])</div><div class="line">  .controller(<span class="string">&apos;DemoCtrl&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">    <span class="comment">// code here</span></div><div class="line">  })</div></pre></td></tr></table></figure>
<p>&#x7B2C;&#x4E09;&#x79CD;&#xFF1A;&#x6700;&#x6B63;&#x786E;&#x7684;&#x65B9;&#x5F0F;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x89E3;&#x51B3;&#x56E0;&#x4E3A;&#x4EE3;&#x7801;&#x538B;&#x7F29;&#x9020;&#x6210;&#x6CE8;&#x5165;&#x5BF9;&#x8C61;&#x5931;&#x8D25;&#x95EE;&#x9898;&#x7684;&#x65B9;&#x5F0F;&#x5C31;&#x662F;&#x5C06;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x6362;&#x6210;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;</span></div><div class="line">angular.module(<span class="string">&apos;DemoApp&apos;</span>, [])</div><div class="line">  .controller(<span class="string">&apos;DemoCtrl&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="string">&apos;$log&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope, $log</span>) </span>{</div><div class="line">    <span class="comment">// code here</span></div><div class="line">  }])</div></pre></td></tr></table></figure>
<p>&#x63A7;&#x5236;&#x5668;&#x5B9A;&#x4E49;&#x4F8B;&#x5B50;&#xFF1A;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>ng - &#x63A7;&#x5236;&#x5668;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;Demo1Controller&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;Demo2Controller&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;js/angular-1.2.3.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    <span class="comment">// &#x5728; ng 1.5 &#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x4E0D;&#x5141;&#x8BB8;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;&#x4E86;</span></div><div class="line">    <span class="comment">// &#x4E4B;&#x524D;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#x7684;&#x65B9;&#x5F0F;&#x4E5F;&#x6709;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x5C31;&#x662F;&#x6A21;&#x5757;&#x5316;&#xFF0C;&#x5DF2;&#x4E0D;&#x518D;&#x4F7F;&#x7528;</span></div><div class="line">    <span class="function"><span class="keyword">function</span> <span class="title">DemoController</span>(<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.foo = <span class="string">&apos;bar&apos;</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// &#x521B;&#x5EFA;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x542F;&#x7528;&#x6807;&#x8BC6;&#x7B26;&#x6DF7;&#x6DC6;&#x538B;&#x7F29;&#x4F1A;&#x628A; $scope &#x538B;&#x7F29;&#x6389;&#xFF0C;&#x4EE3;&#x7801;&#x5C31;&#x62A5;&#x9519;&#x4E86;</span></div><div class="line">    <span class="keyword">var</span> demoApp = angular.module(<span class="string">&apos;DemoApp&apos;</span>, []).controller(<span class="string">&apos;DemoController&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;DemoController&apos;</span>;</div><div class="line">    });</div><div class="line"></div><div class="line">    <span class="comment">// &#x901A;&#x8FC7;&#x6A21;&#x5757;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;</span></div><div class="line">    demoApp.controller(<span class="string">&apos;Demo1Controller&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo1Controller&apos;</span>;</div><div class="line">    });</div><div class="line"></div><div class="line">    <span class="comment">// &#x8FD9;&#x91CC;&#x8868;&#x793A;&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#xFF0C;&#x524D;&#x63D0;&#x662F; DemoApp &#x5DF2;&#x7ECF;&#x5B9A;&#x4E49;&#x8FC7;&#x4E86;</span></div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>).controller(<span class="string">&apos;Demo2Controller&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo2Controller&apos;</span>;</div><div class="line">    });</div><div class="line"></div><div class="line">    <span class="comment">// &#x4EE5;&#x4E0A;&#x4E09;&#x79CD;&#x5F62;&#x5F0F;&#x90FD;&#x662F;&#x57FA;&#x4E8E;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x94FE;&#x5F0F;&#x7F16;&#x7A0B;&#x3001;&#x901A;&#x8FC7;&#x6A21;&#x5757;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x3001;&#x901A;&#x8FC7;&#x83B7;&#x53D6;&#x6A21;&#x5757;&#x5B9A;&#x4E49; &#x90FD;&#x4E00;&#x6837;&#xFF0C;&#x60F3;&#x7528;&#x54EA;&#x79CD;&#x7528;&#x54EA;&#x79CD;</span></div><div class="line"></div><div class="line">    <span class="comment">// &#x521B;&#x5EFA;&#x63A7;&#x5236;&#x5668;&#x6700;&#x6B63;&#x786E;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x4E0D;&#x4F1A;&#x88AB;&#x6DF7;&#x6DC6;&#x4EE3;&#x7801;&#x538B;&#x7F29;&#x5F71;&#x54CD;</span></div><div class="line">    <span class="keyword">var</span> demoApp = angular.module(<span class="string">&apos;DemoApp&apos;</span>, []).controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;DemoController&apos;</span>;</div><div class="line">    }]);</div><div class="line">    demoApp.controller(<span class="string">&apos;Demo1Controller&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo1Controller&apos;</span>;</div><div class="line">    }]);</div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>).controller(<span class="string">&apos;Demo2Controller&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo2Controller&apos;</span>;</div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<h3 id="&#x5982;&#x4F55;&#x5212;&#x5206;&#x63A7;&#x5236;&#x5668;"><a href="#&#x5982;&#x4F55;&#x5212;&#x5206;&#x63A7;&#x5236;&#x5668;" class="headerlink" title="&#x5982;&#x4F55;&#x5212;&#x5206;&#x63A7;&#x5236;&#x5668;"></a>&#x5982;&#x4F55;&#x5212;&#x5206;&#x63A7;&#x5236;&#x5668;</h3><p>&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x4E2D;&#xFF0C;&#x6309;&#x7167;&#x4E0D;&#x540C;&#x7684;&#x529F;&#x80FD;&#x4E1A;&#x52A1;&#x5212;&#x5206;&#x4E0D;&#x540C;&#x7684;&#x63A7;&#x5236;&#x5668;&#x3002;</p>
<h2 id="&#x6A21;&#x5757;&#xFF1A;Module"><a href="#&#x6A21;&#x5757;&#xFF1A;Module" class="headerlink" title="&#x6A21;&#x5757;&#xFF1A;Module"></a>&#x6A21;&#x5757;&#xFF1A;Module</h2><ul>
<li>&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;</li>
<li>&#x6A21;&#x5757;&#x662F;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#x4E0D;&#x540C;&#x90E8;&#x5206;&#x7684;&#x5BB9;&#x5668;</li>
<li>&#x6A21;&#x5757;&#x662F;&#x5E94;&#x7528;&#x63A7;&#x5236;&#x5668;&#x7684;&#x5BB9;&#x5668;</li>
<li>&#x63A7;&#x5236;&#x5668;&#x901A;&#x5E38;&#x5C5E;&#x4E8E;&#x4E00;&#x4E2A;&#x6A21;&#x5757;</li>
</ul>
<p>ng &#x4E2D;&#x6A21;&#x5757;&#x7684;&#x5F15;&#x5165;&#x6700;&#x91CD;&#x8981;&#x7684;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x539F;&#x6765;&#x5168;&#x5C40;&#x5B9A;&#x4E49;&#x7684;&#x63A7;&#x5236;&#x5668;&#x6C61;&#x67D3;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x76EE;&#x7684;&#x5C31;&#x662F;&#x8BA9;&#x6211;&#x4EEC;&#x4EE5;&#x6A21;&#x5757;&#x7684;&#x5F62;&#x5F0F;&#x5212;&#x5206;&#x67B6;&#x6784;&#x3002;</p>
<blockquote>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>angular.module()</code> &#x65B9;&#x6CD5;&#x64CD;&#x4F5C;&#x6A21;&#x5757;<br><strong>&#x6CE8;&#x610F;</strong>&#xFF1A;&#x8BE5;&#x65B9;&#x6CD5;&#x53EA;&#x6709;&#x5728;&#x4F20;&#x5165;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#x624D;&#x4F1A;&#x521B;&#x5EFA;&#x6A21;&#x5757;&#xFF0C;&#x5426;&#x5219;&#x4E3A;&#x83B7;&#x53D6;&#x5DF2;&#x6709;&#x6A21;&#x5757;</p>
</blockquote>
<h3 id="&#x5B9A;&#x4E49;&#x6A21;&#x5757;"><a href="#&#x5B9A;&#x4E49;&#x6A21;&#x5757;" class="headerlink" title="&#x5B9A;&#x4E49;&#x6A21;&#x5757;"></a>&#x5B9A;&#x4E49;&#x6A21;&#x5757;</h3><p>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x6CE8;&#x610F;&#xFF1A;&#x5FC5;&#x987B;&#x6307;&#x5B9A;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5426;&#x5219;&#x53D8;&#x6210;&#x83B7;&#x53D6;&#x5DF2;&#x5B9A;&#x4E49;&#x7684;&#x6A21;&#x5757;</span></div><div class="line"><span class="keyword">var</span> demoApp = angular.module(<span class="string">&apos;DemoApp&apos;</span>, [])</div></pre></td></tr></table></figure>
<p>&#x83B7;&#x53D6;&#x5DF2;&#x6709;&#x6A21;&#x5757;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> demoApp = angular.module(<span class="string">&apos;DemoApp&apos;</span>)</div></pre></td></tr></table></figure>
<p>&#x5B9A;&#x4E49;&#x4F9D;&#x8D56;&#x522B;&#x7684;&#x6A21;&#x5757;&#x7684;&#x6A21;&#x5757;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> demoApp = angular.module(<span class="string">&apos;DemoApp&apos;</span>, [<span class="string">&apos;Module1&apos;</span>, <span class="string">&apos;Module2&apos;</span>])</div></pre></td></tr></table></figure>
<blockquote>
<p>&#x5B9A;&#x4E49;&#x6A21;&#x5757;&#x548C;&#x63A7;&#x5236;&#x5668;(&#x5229;&#x7528;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;)</p>
</blockquote>
<ol>
<li>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6A21;&#x5757; <code>angular.module(&apos;&#x6A21;&#x5757;&#x540D;&apos;, [])</code><ul>
<li>&#x5982;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5C31;&#x8868;&#x793A;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x6A21;&#x5757;</li>
<li>&#x5982;&#x679C;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x5FC5;&#x987B;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;<ul>
<li>&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x8868;&#x793A;&#x8BE5;&#x6A21;&#x5757;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x7A7A;&#x6570;&#x7EC4;&#x8868;&#x793A;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x4F9D;&#x8D56;&#xFF0C;&#x540C;&#x65F6;&#x521B;&#x5EFA;&#x8BE5;&#x6A21;&#x5757;</li>
<li>&#x5982;&#x679C;&#x6709;&#x4F9D;&#x8D56;&#xFF0C;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x6307;&#x5B9A;&#x4F9D;&#x8D56;&#x7684;&#x6A21;&#x5757;&#x540D;&#x5373;&#x53EF;</li>
</ul>
</li>
</ul>
</li>
<li>&#x5728;&#x8BE5;&#x6A21;&#x5757;&#x4E0B;&#x53BB;&#x5B9A;&#x4E49;&#x63A7;&#x5236;&#x5668;</li>
<li>&#x5C06;&#x6A21;&#x5757;&#x548C;&#x63A7;&#x5236;&#x5668;&#x4F5C;&#x7528;&#x5230;&#x89C6;&#x56FE;</li>
</ol>
<h3 id="&#x5982;&#x4F55;&#x5212;&#x5206;&#x6A21;&#x5757;"><a href="#&#x5982;&#x4F55;&#x5212;&#x5206;&#x6A21;&#x5757;" class="headerlink" title="&#x5982;&#x4F55;&#x5212;&#x5206;&#x6A21;&#x5757;"></a>&#x5982;&#x4F55;&#x5212;&#x5206;&#x6A21;&#x5757;</h3><h3 id="&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x6A21;&#x5757;"><a href="#&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x6A21;&#x5757;" class="headerlink" title="&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x6A21;&#x5757;"></a>&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x6A21;&#x5757;</h3><ul>
<li><code>angular.bootstrap(document, [&apos;demo&apos;])</code></li>
<li><code>angular.module(&apos;MainModule&apos;, [&apos;Module1&apos;, &apos;Module2&apos;, &apos;Module3&apos;[,ModuleName]])</code></li>
</ul>
<p>&#x6A21;&#x5757;&#x4F8B;&#x5B50;&#xFF1A;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>ng - &#x6A21;&#x5757;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;MainModule&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;Demo1Controller&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;Demo2Controller&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">ng-controller</span>=<span class="string">&quot;MainController&quot;</span>&gt;</span></div><div class="line">    {{name}}</div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    <span class="comment">// &#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF08;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x4F9D;&#x8D56;&#x9879;&#xFF09;</span></div><div class="line">    <span class="comment">// Angular &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x4E0D;&#x50CF;&#x4E00;&#x4E9B; CMD&#x3001;CommonJS&#x3001;AMD &#x7B49;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x89C4;&#x8303;</span></div><div class="line">    <span class="comment">//         &#x6709;&#x8F93;&#x5165;&#x6709;&#x8F93;&#x51FA;</span></div><div class="line">    <span class="comment">//         Angular &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x8F93;&#x5165;&#x4E0E;&#x8F93;&#x51FA;&#xFF08;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x4F9D;&#x8D56;&#x3001;&#x66B4;&#x9732;&#x6A21;&#x5757;&#x6210;&#x5458;&#xFF09;&#x4F53;&#x73B0;&#x4E0D;&#x591F;&#x660E;&#x663E;</span></div><div class="line">    <span class="comment">// Angular &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x4E5F;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x4EE3;&#x7801;&#x53BB;&#x4E3B;&#x52A8;&#x7684;&#x52A0;&#x8F7D;&#x53E6;&#x4E00;&#x4E2A;&#x6A21;&#x5757;</span></div><div class="line">    <span class="comment">// Angular &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x552F;&#x4E00;&#x4F53;&#x73B0;&#x7684;&#x5730;&#x65B9;&#x5728;&#x4E8E;&#xFF1A;</span></div><div class="line">    <span class="comment">//    1. &#x89E3;&#x51B3;&#x539F;&#x6765;&#x5168;&#x5C40;&#x63A7;&#x5236;&#x5668;&#x547D;&#x540D;&#x6C61;&#x67D3;&#x7684;&#x95EE;&#x9898;</span></div><div class="line">    <span class="comment">//    2. &#x89E3;&#x51B3;&#x6309;&#x7167;&#x4E0D;&#x540C;&#x7684;&#x9875;&#x9762;&#xFF0C;&#x5C06;&#x4E0D;&#x540C;&#x7684;&#x63A7;&#x5236;&#x5668;&#x7EC4;&#x7EC7;&#x5230;&#x4E00;&#x8D77;</span></div><div class="line">    angular.module(<span class="string">&apos;Demo1App&apos;</span>, []).controller(<span class="string">&apos;Demo1Controller&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo1Controller&apos;</span>;</div><div class="line">    }]).controller(<span class="string">&apos;MainController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span>(<span class="params">$scope</span>)</span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo1App MainController&apos;</span>;</div><div class="line">    }]);</div><div class="line"></div><div class="line">    angular.module(<span class="string">&apos;Demo2App&apos;</span>, []).controller(<span class="string">&apos;Demo2Controller&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;Demo2Controller&apos;</span>;</div><div class="line">    }]);</div><div class="line"></div><div class="line">    <span class="comment">// &#x624B;&#x52A8;&#x5F15;&#x5BFC;&#x6A21;&#x5757;&#x7684;&#x542F;&#x52A8;&#xFF0C;&#x53EF;&#x4EE5;&#x542F;&#x52A8;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x4F46;&#x662F;&#x90FD;&#x5FC5;&#x987B;&#x4F5C;&#x7528;&#x5230;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E0A;&#xFF1B;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;</span></div><div class="line">    angular.bootstrap(<span class="built_in">document</span>.getElementById(<span class="string">&apos;body&apos;</span>), [<span class="string">&apos;Demo1App&apos;</span>, <span class="string">&apos;Demo2App&apos;</span>]);</div><div class="line"></div><div class="line">    <span class="comment">// &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x4E3B;&#x6A21;&#x5757;&#xFF0C;&#x52A0;&#x8F7D;&#x4F9D;&#x8D56;&#x7684;&#x6A21;&#x5757;</span></div><div class="line">    angular.module(<span class="string">&apos;MainModule&apos;</span>, [<span class="string">&apos;Demo1App&apos;</span>, <span class="string">&apos;Demo2App&apos;</span>]).controller(<span class="string">&apos;MainController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>{</div><div class="line">      $scope.name = <span class="string">&apos;MainModule MainController&apos;</span>;</div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<h2 id="&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;Filter"><a href="#&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;Filter" class="headerlink" title="&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;Filter"></a>&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;Filter</h2><h3 id="&#x5185;&#x7F6E;&#x8FC7;&#x6EE4;&#x5668;"><a href="#&#x5185;&#x7F6E;&#x8FC7;&#x6EE4;&#x5668;" class="headerlink" title="&#x5185;&#x7F6E;&#x8FC7;&#x6EE4;&#x5668;"></a>&#x5185;&#x7F6E;&#x8FC7;&#x6EE4;&#x5668;</h3><ul>
<li>currency</li>
<li>number</li>
<li>date</li>
<li>json</li>
<li>uppercase</li>
<li>lowercase</li>
<li>orderBy</li>
<li>limitTo</li>
<li>filter</li>
</ul>
<h3 id="&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;"><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;" class="headerlink" title="&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;"></a>&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">&quot;DemoApp&quot;</span> <span class="attr">ng-controller</span>=<span class="string">&quot;DemoController&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{time | date:&apos;yyyy-MM-dd HH:mm:ss&apos;}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{time | date:&apos;yyyy-MM-dd HH:mm:ss Z&apos;}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{time | date:&apos;yyyy-MM-dd HH:mma&apos;}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{time | date:&apos;medium&apos;}}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>{{ user | json }}<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">pre</span>&gt;</span>{{ user | json:4 }}<span class="tag">&lt;/<span class="name">pre</span>&gt;</span><span class="tag">&lt;<span class="name">hr</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">label</span> <span class="attr">for</span>=<span class="string">&quot;&quot;</span>&gt;</span>&#x641C;&#x7D22;&#xFF1A;<span class="tag">&lt;/<span class="name">label</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;searchText&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">table</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">thead</span>&gt;</span><span class="tag">&lt;<span class="name">tr</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x59D3;&#x540D;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x7535;&#x8BDD;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span><span class="tag">&lt;/<span class="name">thead</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">tbody</span>&gt;</span><span class="tag">&lt;<span class="name">tr</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;friend in friends | filter:searchText track by $index&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.name}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.phone}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span><span class="tag">&lt;/<span class="name">tbody</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">table</span>&gt;</span><span class="tag">&lt;<span class="name">hr</span>&gt;</span><span class="tag">&lt;<span class="name">hr</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">label</span>&gt;</span>&#x5339;&#x914D;&#x4EFB;&#x610F;&#x9879;: <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">&quot;search.$&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">label</span>&gt;</span> <span class="tag">&lt;<span class="name">br</span>&gt;</span> {$: &apos;xxx&apos;}</div><div class="line">  <span class="tag">&lt;<span class="name">label</span>&gt;</span>&#x6839;&#x636E;&#x540D;&#x5B57;&#x7B5B;&#x9009;&#xFF1A; <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">&quot;search.name&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">label</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span> {name: &apos;xxx&apos;}</div><div class="line">  <span class="tag">&lt;<span class="name">label</span>&gt;</span>Phone only <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">&quot;search.phone&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">label</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span> {phone: &apos;xxx&apos;}</div><div class="line">  <span class="tag">&lt;<span class="name">label</span>&gt;</span>Equality <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">ng-model</span>=<span class="string">&quot;strict&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">label</span>&gt;</span> </div><div class="line">  <span class="tag">&lt;<span class="name">table</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">thead</span>&gt;</span><span class="tag">&lt;<span class="name">tr</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x59D3;&#x540D;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;<span class="name">th</span>&gt;</span>&#x7535;&#x8BDD;<span class="tag">&lt;/<span class="name">th</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span><span class="tag">&lt;/<span class="name">thead</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">tbody</span>&gt;</span><span class="tag">&lt;<span class="name">tr</span> <span class="attr">ng-repeat</span>=<span class="string">&quot;friend in friends | filter:search:strict track by $index&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">td</span>&gt;</span>{{friend.name}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span>td&gt;{{friend.phone}}<span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span><span class="tag">&lt;/<span class="name">tbody</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">table</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../code/js/angular.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    angular.module(<span class="string">&apos;DemoApp&apos;</span>, []);.controller(<span class="string">&apos;DemoController&apos;</span>, [<span class="string">&apos;$scope&apos;</span>,<span class="string">&apos;$filter&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope, $filter</span>) </span>{</div><div class="line">      $scope.time = <span class="keyword">new</span> <span class="built_in">Date</span>();</div><div class="line">      $scope.user = {<span class="attr">name</span>: <span class="string">&apos;Jack&apos;</span>,<span class="attr">age</span>: <span class="number">18</span>};</div><div class="line">      <span class="built_in">console</span>.log($filter(<span class="string">&apos;date&apos;</span>)($scope.time, <span class="string">&apos;yyyy-MM-dd HH:mm:ss&apos;</span>));</div><div class="line">      $scope.friends = [{<span class="attr">name</span>:<span class="string">&apos;John&apos;</span>, <span class="attr">phone</span>:<span class="string">&apos;555-1276&apos;</span>},{<span class="attr">name</span>:<span class="string">&apos;Mary&apos;</span>, <span class="attr">phone</span>:<span class="string">&apos;800-BIG-MARY&apos;</span>},{<span class="attr">name</span>:<span class="string">&apos;Mike&apos;</span>, <span class="attr">phone</span>:<span class="string">&apos;555-4321&apos;</span>}];</div><div class="line">      $scope.searchText = <span class="string">&apos;&apos;</span>;</div><div class="line">      $scope.search = {};</div><div class="line">    }]);</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div></pre></td></tr></table></figure>
<h2 id="&#x670D;&#x52A1;&#xFF1A;Service"><a href="#&#x670D;&#x52A1;&#xFF1A;Service" class="headerlink" title="&#x670D;&#x52A1;&#xFF1A;Service"></a>&#x670D;&#x52A1;&#xFF1A;Service</h2><p>&#x5728; Angular &#x4E2D;&#xFF0C;&#x670D;&#x52A1;&#x7684;&#x6982;&#x5FF5;&#x548C;&#x540E;&#x53F0;&#x7684;&#x670D;&#x52A1;&#x6982;&#x5FF5;&#x57FA;&#x672C;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x5DEE;&#x522B;&#x53EA;&#x662F;&#x5728;&#x4E8E;&#x6280;&#x672F;&#x7EC6;&#x8282;&#x3002;</p>
<p>&#x670D;&#x52A1;&#x662F;&#x5BF9;&#x516C;&#x5171;&#x4EE3;&#x7801;&#x7684;&#x62BD;&#x8C61;&#xFF0C;&#x6BD4;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x591A;&#x4E2A;&#x63A7;&#x5236;&#x5668;&#x4E2D;&#x90FD;&#x51FA;&#x73B0;&#x4E86;&#x76F8;&#x4F3C;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x90A3;&#x4E48;&#x628A;&#x5B83;&#x4EEC;&#x63D0;&#x53D6;&#x51FA;&#x6765;&#xFF0C;&#x5C01;&#x88C5;&#x6210;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#xFF0C;&#x5728;&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x65B9;&#x9762;&#x83B7;&#x5F97;&#x63D0;&#x5347;&#x3002;</p>
<p>&#x7136;&#x800C;&#xFF0C;&#x5728;&#x5DE5;&#x7A0B;&#x5B9E;&#x8DF5;&#x4E2D;&#xFF0C;&#x5F15;&#x5165;&#x670D;&#x52A1;&#x7684;&#x4E3B;&#x8981;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x4F18;&#x5316;&#x4EE3;&#x7801;&#x7ED3;&#x6784;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x590D;&#x7528;&#x3002;&#x590D;&#x7528;&#x53EA;&#x662F;&#x4E00;&#x9879;&#x7ED3;&#x679C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x76EE;&#x6807;&#x3002;</p>
<h2 id="Angular-&#x8C03;&#x8BD5;"><a href="#Angular-&#x8C03;&#x8BD5;" class="headerlink" title="Angular &#x8C03;&#x8BD5;"></a>Angular &#x8C03;&#x8BD5;</h2><h3 id="&#x5C06;-scope-&#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x6302;&#x8F7D;&#x7ED9;-window"><a href="#&#x5C06;-scope-&#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x6302;&#x8F7D;&#x7ED9;-window" class="headerlink" title="&#x5C06; $scope &#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x6302;&#x8F7D;&#x7ED9; window"></a>&#x5C06; $scope &#x6A21;&#x578B;&#x5BF9;&#x8C61;&#x6302;&#x8F7D;&#x7ED9; window</h3><p>&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#xFF0C;&#x9EBB;&#x70E6;</p>
<h3 id="Chrome-&#x63D2;&#x4EF6;&#xFF1A;AngularJS-Batarang"><a href="#Chrome-&#x63D2;&#x4EF6;&#xFF1A;AngularJS-Batarang" class="headerlink" title="Chrome &#x63D2;&#x4EF6;&#xFF1A;AngularJS Batarang"></a>Chrome &#x63D2;&#x4EF6;&#xFF1A;AngularJS Batarang</h3><ul>
<li>&#x5B89;&#x88C5;&#x63D2;&#x4EF6;</li>
</ul>
<p>&#x57FA;&#x672C;&#x4F7F;&#x7528;&#xFF1A;</p>
<ol>
<li>&#x4EE5; http &#x534F;&#x8BAE;&#x8BBF;&#x95EE;&#x4F60;&#x8981;&#x8C03;&#x8BD5;&#x7684;&#x9875;&#x9762;</li>
<li>&#x6253;&#x5F00;&#x63A7;&#x5236;&#x53F0;&#xFF0C;&#x627E;&#x5230; AngularJS</li>
<li>&#x9009;&#x62E9; Enable &#x542F;&#x7528;&#x8C03;&#x8BD5;</li>
<li>&#x5207;&#x6362;&#x5230; Scope &#x9009;&#x9879;&#x5361;</li>
</ol>
<h2 id="MVVM"><a href="#MVVM" class="headerlink" title="MVVM"></a>MVVM</h2><h3 id="M-Model"><a href="#M-Model" class="headerlink" title="M: Model"></a>M: Model</h3><p>M: &#x6570;&#x636E;&#x6A21;&#x578B;</p>
<h3 id="V"><a href="#V" class="headerlink" title="V"></a>V</h3><p>V: &#x89C6;&#x56FE;</p>
<h3 id="VM"><a href="#VM" class="headerlink" title="VM"></a>VM</h3><p>ViewModel: &#x89C6;&#x56FE;&#x6A21;&#x578B;</p>
<h3 id="C"><a href="#C" class="headerlink" title="C"></a>C</h3><p>&#x7528;&#x6765;&#x5904;&#x7406;&#x89C6;&#x56FE;&#x6A21;&#x578B;&#x548C;&#x89C6;&#x56FE;&#x7684;&#x4EA4;&#x4E92;&#x7684;</p>
<h2 id="&#x4F7F;&#x7528;-ng-&#x603B;&#x7ED3;"><a href="#&#x4F7F;&#x7528;-ng-&#x603B;&#x7ED3;" class="headerlink" title="&#x4F7F;&#x7528; ng &#x603B;&#x7ED3;"></a>&#x4F7F;&#x7528; ng &#x603B;&#x7ED3;</h2><ul>
<li>AngularJS &#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x4E0A;&#x51CF;&#x5C11;&#x4E86;&#x9875;&#x9762;&#x4E0A;&#x7684; DOM &#x64CD;&#x4F5C;</li>
<li>&#x8BA9;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x66F4;&#x4E13;&#x6CE8;&#x4E8E;&#x4E1A;&#x52A1;&#x64CD;&#x4F5C;</li>
<li>&#x901A;&#x8FC7;&#x7B80;&#x6D01;&#x7684;&#x6307;&#x4EE4;&#x7ED3;&#x5408;&#x9875;&#x9762;&#x7ED3;&#x6784;&#x4E0E;&#x903B;&#x8F91;&#x6570;&#x636E;</li>
<li>&#x901A;&#x8FC7;&#x81EA;&#x5B9A;&#x4E49;&#x6307;&#x4EE4;&#x5B9E;&#x73B0;&#x7EC4;&#x4EF6;&#x5316;&#x7F16;&#x7A0B;</li>
<li>&#x4EE3;&#x7801;&#x7ED3;&#x6784;&#x66F4;&#x5408;&#x7406;</li>
<li>&#x7EF4;&#x62A4;&#x6210;&#x672C;&#x66F4;&#x4F4E;</li>
<li>AngularJS &#x89E3;&#x653E;&#x4E86;&#x4F20;&#x7EDF; JavaScript &#x4E2D;&#x9891;&#x7E41;&#x7684; DOM &#x64CD;&#x4F5C;</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>感谢您的支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>打 赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Node-js/" rel="tag">#Node.js</a>
          
            <a href="/tags/框架/" rel="tag">#框架</a>
          
            <a href="/tags/AngularJS/" rel="tag">#AngularJS</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/05/11/25-js-的模块化/" rel="next" title="js 的模块化">
                <i class="fa fa-chevron-left"></i> js 的模块化
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/07/05/27-AngularJS-项目流程/" rel="prev" title="AngularJS 项目流程">
                AngularJS 项目流程 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/06/18/26-AngularJS-框架/"
     data-title="AngularJS 框架"
     data-content=""
     data-url="https://hongqinma.github.io/2015/06/18/26-AngularJS-框架/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/06/18/26-AngularJS-框架/"
           data-title="AngularJS 框架" data-url="https://hongqinma.github.io/2015/06/18/26-AngularJS-框架/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">68</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Angular-介绍"><span class="nav-number">1.</span> <span class="nav-text">Angular 介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是框架和库"><span class="nav-number">1.1.</span> <span class="nav-text">什么是框架和库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是-AngularJS"><span class="nav-number">1.2.</span> <span class="nav-text">什么是 AngularJS</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#为什么使用-Angular"><span class="nav-number">1.3.</span> <span class="nav-text">为什么使用 Angular</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#AngularJS-优缺点"><span class="nav-number">1.4.</span> <span class="nav-text">AngularJS 优缺点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#AngularJS-使用场景"><span class="nav-number">1.5.</span> <span class="nav-text">AngularJS 使用场景</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#AngularJS资源"><span class="nav-number">1.6.</span> <span class="nav-text">AngularJS资源</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SPA-单页面应用程序"><span class="nav-number">2.</span> <span class="nav-text">SPA 单页面应用程序</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#传统的网站模型：多页面应用模型"><span class="nav-number">2.1.</span> <span class="nav-text">传统的网站模型：多页面应用模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SPA-网站模型"><span class="nav-number">2.2.</span> <span class="nav-text">SPA 网站模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#利用锚点改变网页内容"><span class="nav-number">2.3.</span> <span class="nav-text">利用锚点改变网页内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#单页应用的好处"><span class="nav-number">2.4.</span> <span class="nav-text">单页应用的好处</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何在网页中解析-URL-地址"><span class="nav-number">2.5.</span> <span class="nav-text">如何在网页中解析 URL 地址</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Angular-的应用"><span class="nav-number">3.</span> <span class="nav-text">Angular 的应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#关于版本"><span class="nav-number">3.1.</span> <span class="nav-text">关于版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装"><span class="nav-number">3.2.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#第一个-Angular-程序"><span class="nav-number">3.3.</span> <span class="nav-text">第一个 Angular 程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码解析"><span class="nav-number">3.4.</span> <span class="nav-text">代码解析</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#AngularJS-表达式"><span class="nav-number">4.</span> <span class="nav-text">AngularJS 表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#基本使用"><span class="nav-number">4.1.</span> <span class="nav-text">基本使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#支持的类型及操作符"><span class="nav-number">4.2.</span> <span class="nav-text">支持的类型及操作符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Angular-表达式与-JavaScript-区别："><span class="nav-number">4.3.</span> <span class="nav-text">Angular 表达式与 JavaScript 区别：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解决表达式闪烁的问题"><span class="nav-number">4.4.</span> <span class="nav-text">解决表达式闪烁的问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#AngularJS-指令"><span class="nav-number">5.</span> <span class="nav-text">AngularJS 指令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#指令的使用形式"><span class="nav-number">6.</span> <span class="nav-text">指令的使用形式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#内置指令"><span class="nav-number">6.1.</span> <span class="nav-text">内置指令</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ngApp"><span class="nav-number">6.1.1.</span> <span class="nav-text">ngApp</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngController"><span class="nav-number">6.1.2.</span> <span class="nav-text">ngController</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngInit"><span class="nav-number">6.1.3.</span> <span class="nav-text">ngInit</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngBind"><span class="nav-number">6.1.4.</span> <span class="nav-text">ngBind</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngBindHtml"><span class="nav-number">6.1.5.</span> <span class="nav-text">ngBindHtml</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngRepeat"><span class="nav-number">6.1.6.</span> <span class="nav-text">ngRepeat</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决重复项报错问题"><span class="nav-number">6.1.7.</span> <span class="nav-text">解决重复项报错问题</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ngClass"><span class="nav-number">6.1.8.</span> <span class="nav-text">ngClass</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ng-cloak"><span class="nav-number">6.1.9.</span> <span class="nav-text">ng-cloak</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ng-hide-show-if-switch"><span class="nav-number">6.1.10.</span> <span class="nav-text">ng-hide-show-if-switch</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ng-src"><span class="nav-number">6.1.11.</span> <span class="nav-text">ng-src</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#其它常用指令"><span class="nav-number">6.1.12.</span> <span class="nav-text">其它常用指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#事件型指令"><span class="nav-number">6.1.13.</span> <span class="nav-text">事件型指令</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#视图数据模型：-scope"><span class="nav-number">7.</span> <span class="nav-text">视图数据模型：$scope</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#如何设计-scope"><span class="nav-number">7.1.</span> <span class="nav-text">如何设计 $scope</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ViewModel"><span class="nav-number">7.2.</span> <span class="nav-text">ViewModel</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数据模型作用域"><span class="nav-number">7.3.</span> <span class="nav-text">数据模型作用域</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#控制器：Controller"><span class="nav-number">8.</span> <span class="nav-text">控制器：Controller</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#定义控制器的三种方式"><span class="nav-number">8.1.</span> <span class="nav-text">定义控制器的三种方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何划分控制器"><span class="nav-number">8.2.</span> <span class="nav-text">如何划分控制器</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块：Module"><span class="nav-number">9.</span> <span class="nav-text">模块：Module</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#定义模块"><span class="nav-number">9.1.</span> <span class="nav-text">定义模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何划分模块"><span class="nav-number">9.2.</span> <span class="nav-text">如何划分模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#加载多个模块"><span class="nav-number">9.3.</span> <span class="nav-text">加载多个模块</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#过滤器：Filter"><span class="nav-number">10.</span> <span class="nav-text">过滤器：Filter</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#内置过滤器"><span class="nav-number">10.1.</span> <span class="nav-text">内置过滤器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义过滤器"><span class="nav-number">10.2.</span> <span class="nav-text">自定义过滤器</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#服务：Service"><span class="nav-number">11.</span> <span class="nav-text">服务：Service</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Angular-调试"><span class="nav-number">12.</span> <span class="nav-text">Angular 调试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#将-scope-模型对象挂载给-window"><span class="nav-number">12.1.</span> <span class="nav-text">将 $scope 模型对象挂载给 window</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Chrome-插件：AngularJS-Batarang"><span class="nav-number">12.2.</span> <span class="nav-text">Chrome 插件：AngularJS Batarang</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MVVM"><span class="nav-number">13.</span> <span class="nav-text">MVVM</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#M-Model"><span class="nav-number">13.1.</span> <span class="nav-text">M: Model</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#V"><span class="nav-number">13.2.</span> <span class="nav-text">V</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#VM"><span class="nav-number">13.3.</span> <span class="nav-text">VM</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#C"><span class="nav-number">13.4.</span> <span class="nav-text">C</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用-ng-总结"><span class="nav-number">14.</span> <span class="nav-text">使用 ng 总结</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
